[Tutor] file move with wait period

Mats Wichmann mats at wichmann.us
Fri Aug 4 00:23:28 EDT 2017


On 08/03/2017 05:22 AM, banda gunda 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?
> 
> 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?

Well, we cannot answer that question with the information you have given.

"How can you know" is actually the key question to explore. You need to
answer it before you worry about any Pythonic implementation details of
solving your problem.

- is the decompressor initiated by your program?  In that case there
will be techniques to maintain communication with it to find out when it
is done (perhaps as simple as waiting for it to quit-with-success).
- if it launches completely independently, how do you find out that it
has deposited files? Do you intend to just can periodically? Or is there
a way that the system causing the files to be generated can trigger
something that your program could be asked to be notified about when a
file is available?
- is it possible to convice the compressor to give files a certain
suffix or other recognizable pattern, but only when they are complete?
(downloader systems often work like this... while they're writing the
file, it has some temporary name, then when it finishes it is renamed to
the intended target name).

and so on.


More information about the Tutor mailing list