AutoHotkey Community

It is currently May 26th, 2012, 11:31 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: File In Use Question
PostPosted: November 14th, 2008, 8:42 am 
Offline

Joined: May 14th, 2007, 10:39 pm
Posts: 6
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 November 15th, 2008, 6:47 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: File In Use Question
PostPosted: November 14th, 2008, 2:25 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
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
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 15th, 2008, 6:49 am 
Offline

Joined: May 14th, 2007, 10:39 pm
Posts: 6
Thanks SKAN.

You make it look so simple. Thanks again.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: 0x150||ISO, BrandonHotkey, Exabot [Bot], Yahoo [Bot] and 43 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group