I have written a small script to watch a file folder and watch for new files that are put into the folder. Another program (MCE Buddy) converts video files and populates the folder. I am trying to run a another batch file once the file conversion is complete.
My first thought was to identify the completed files by looking at the file sizes and then returning to them later and see if there is a change in the file size. Unfortunately, the files sizes appear to same even though the file continues to be in use (and continues to grow).
Here is the code I used: (the Temp.txt contains files names for the new files previously identified)
Code:
Loop, Read, temp.txt
{
FileGetSize, FileSize, %A_LoopReadLine%,
sleep, 15000 ;wait 15sec
FileGetSize, FileSize2, %A_LoopReadLine%,
FormatTime, TimeString,,
FileAppend,%TimeString%`nFile:%A_LoopReadLine%`nFileSize At First Check:%FileSize% bytes `nFileSize at Second Check %FileSize2% bytes`n`n`n, FileSizeRecord.log
If (FileSize<FileSize2 ) ;Check if the file is growing
Fileappend,%A_LoopReadLine%`n, temp2.txt
else ;Else if the file is not growing
{
FormatTime, CurrentTime,,Shortdate
Fileappend, %CurrentTime%: %A_LoopReadLine% `n, CompletedFiles.log
Runwait, "%BatchfileLoc%" "%A_LoopReadLine%",, Hide
}
It appears that the file sizes are the same via AKH even though the file is growing as per windows explorer. It appears that GetFileSize can not identify the growth in a file. I have also tried this with copying a large file over the network to the shared directory that it being watched by the above script, and this too fails (FileGetSize reports a non growing file).
The workaround that I have come up with (which works) is to attempt to copy the video file, if I get an error (from errorlevel being 1) then that means that the files continues to be in use and I can not go to the run next step on the completed file.
This works but is not the solution I expected. Any ideas why FileGetSize does not change when the file is use. Are there better ways to see if a file is complete and no longer in use?
Thanks.