I am trying to find a script that will detect if a file is done copying.
The specific situation is a large file (~500MB) coming across a network into a watched folder. The folder action is supposed to activate once the file is done copying. Even though the first line of the folder action is:
on adding folder items to my_folder after receiving the_files
… AFTER RECEIVING… the script still starts before the files are done.
I tried both of these methods for detecting if a file is “busy”:
busy status of (info for alias "MacHD:some file.txt")
open for access file x
--> file is not busy (ie, it's not locked and you can write data to it)
close access result
--> file is busy
From here: http://macscripter.net/viewtopic.php?id=24428
They both always return true, making them useless. Any ideas?
I found this Handler somewhere (not tested):
--Tests to see if a file is in use
set myscript to "if ( lsof -Fp " & thePath & " | grep -q p[0-9]* ) then echo 'file is busy'; else echo 'not busy';fi"
set myResult to do shell script myscript
if myResult is "not busy" then
on error err
--display dialog ("Error: isFileBusy " & err) giving up after 5
set timeDelay to 15 -- the time to wait between size checks in seconds
set sizeThen to size of (info for file (theFile as text)) --get initial size
set sizeNow to size of (info for file theFile) -- get new size
if sizeNow - sizeThen is less than or equal to 0 then exit repeat
set sizeThen to sizeNow