[Tutor] Checking a file size before moving it

Alfred Milgrom fredm@smartypantsco.com
Fri Jan 31 05:19:02 2003


OK - I note that no-one has ventured any suggestions, so here is a start 
from someone who knows nothing about file systems!

I assume that there is no simple way to tell if a file is being accessed.

One suggestion would be to look at the timestamp. Since you sweep every 15 
minutes, ignore ay files that have been created since the last sweep, but 
transfer only those files that were created more than 15 minutes earlier.

Another suggestion might be to copy the files rather than moving them, and 
at the end of the operation check whether the size of the files is the 
same. If yes, you can remove the file from Directory A.

I'm sure there's a better way out there than waiting 10 seconds!

HTH,
Fred Milgrom

At 09:14 PM 30/01/03 -0800, you wrote:
>Hello to all,
>
>I am writing a Python script that is intended to move
>some files from directory A to directory B on a
>server. Users copy the files to directory A once
>daily. The Python script is triggered by a scheduler
>and sweeps the directory for the files every 15
>minutes. Obviously, I need to check that a file has
>been completely written before attempting to move it.
>On the Unix platform, I use the following scheme to
>ascertain that a file is no longer being written:
>
>stat the file and get its size(size1)
>sleep for 10 seconds
>stat the file again and get its size(size2)
>if size2 == size1 proceed with the move operation
>
>This works fine in Unix but I am not sure sleep works
>OK in Win32 since I had some problems in the past
>doing something similar with VB6. The timer would
>sometimes trigger at the same time the files were
>being
>copied and incomplete files were moved to the target
>directory.
>
>Can anybody suggest a different way of checking if the
>copy operation has been completed?
>
>Thanks,
>Levy Lazarre