On 03Aug2017 11:22, banda gunda <bandagu...@hotmail.com> wrote:
Dear tutors,

I am interested to move a set of files, periodically, from source_folder to 
dest_folder.
source_folder receives processed files from a ‘decompressing program’.  The 
files are deposited from the ‘decompressing program’ at periodic random 
intervals.  Furthermore some of the files dropped in the source_folder are 
large, of typical size 800MB.  These files take time before it is completely 
deposited in the source_folder.

I could use shutil.move (source_folder, dest_folder).  But then how?

You'd normally use shutil.move(source_file, dest_file) i.e. move individual files. Or os.rename, but that requires that the source and dest are the same filesystem.

The frequency of moving files from source_folder to dest_folder is flexible.  
It could be once in 15 minutes (or even lengthier).
Challenge for me:  How could the code include the wait statement to make sure 
that the file in the source_folder is completely formed before attempting to 
move to dest_folder?
Thanks in advance for your comments/guidance.

That is the tricky thing; this shows up a lot, also with FTP upload locations and so forth.

The problem, as you state, is knowing when the file is complete. There are 2 basic approaches: do not put a fil into the transfer directory before it is complete, or to monitor the files for changes. On the premise that the file will be being actively written until it is complete you could keep a list if the files in the directory. For each name, record the file's size and modification time. Wait for that to be unchanged "long enough"; you might then decide it is ready to move.

Cheers,
Cameron Simpson <c...@cskk.id.au> (formerly c...@zip.com.au)
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to