 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
rtmey2000
Joined: 14 May 2007 Posts: 6
|
Posted: Fri Nov 14, 2008 7:42 am Post subject: File In Use Question |
|
|
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.
Last edited by rtmey2000 on Sat Nov 15, 2008 5:47 am; edited 1 time in total |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Fri Nov 14, 2008 1:25 pm Post subject: Re: File In Use Question |
|
|
| rtmey2000 wrote: | | Are there better ways to see if a file is complete and no longer in use? |
| Code: | Loop, %A_Temp%\*.*,0,1
{
If FileInUse( A_LoopFileLongPath )
MsgBox, 0,File in Use, %A_LoopFileLongPath%
}
FileInUse( F ) {
Return ((h:=DllCall("_lopen",Str,F,Int,16))>0 ? 0 : 1) (DllCall("_lclose",Int,h)+NULL)
} |
Be aware that FileInUse() will return a True if the File does not Exist. You may use FileExist() to test it _________________ URLGet - Internet Explorer based Downloader |
|
| Back to top |
|
 |
rtmey2000
Joined: 14 May 2007 Posts: 6
|
Posted: Sat Nov 15, 2008 5:49 am Post subject: |
|
|
Thanks SKAN.
You make it look so simple. Thanks again. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|