Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if a file is 'complete' (with python)

is it possible to check if a file is done copying of if its complete using python?
or even on the command line.
i manipulate files programmatically in a specific folder on mac osx but i need to check if the file is complete before running the code which makes the manipulation.

like image 779
aschmid00 Avatar asked Mar 03 '26 05:03

aschmid00


2 Answers

There's no notion of "file completeness" in the Unix/Mac OS X filesystem. You could either try locking the file with flock or, simpler, copy the files to a subdir of the destination directory temporarily, then move them out once they're fully copied (assuming you have control over the program that does the copying). Moving is an atomic operation; you'll know the file is completely copied once it appears at the expected path.

like image 51
Fred Foo Avatar answered Mar 04 '26 19:03

Fred Foo


take the md5 of the file before you copy and then again whenever you think you are done copying. when they match you are good to go. use md5 from the hashlib module for this.

like image 29
sbartell Avatar answered Mar 04 '26 21:03

sbartell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!