BBrian Posted July 18, 2008 Share Posted July 18, 2008 I'm watching a network folder for pdfs and then processing them but if I copy the pdf too soon all I get is a corrupt file. The pdf is being created by a scanner so I guess it makes the filename before the file is ready. How can I tell when it's safe? I tried checking the filesize every second until it has remained stable but I get the same result: Do $checkFileSize = FileGetSize ($newFile) Sleep(1000) $checkFileSize2 = FileGetSize ($newFile) Until $checkFileSize = $checkFileSize2 I think I also tried it with a bigger delay. Currently, I'm waiting 60s after the filename is seen before moving it, but that's hardly ideal. Has anyone any suggestions of attributes I can look at so I can get the file as soon as possible? Link to comment Share on other sites More sharing options...
Mobius Posted July 18, 2008 Share Posted July 18, 2008 DIM $i_Swtch, $i_Count, $ci_Max, $s_File $s_File = "\\SHARE\PDFDOCS\My.pdf" $i_Count = 1 $ci_Max = 60 DO $i_Swtch = _FileReady($s_File) Sleep(1000) $i_Count += 1 UNTIL $i_Swtch <> 1 OR $i_Count >= $ci_Max IF $i_Count >= $ci_Max THEN MsgBox(0,"error","Timed out at "& $ci_Max) EXIT 1 ELSE MsgBox(0,"dummy","Perform Actions on "& $s_File) ; ... Perform actions EXIT ENDIF ; Uses File open for writing flag 1 ; Tried read flag but did not work. FUNC _FileReady($s_F) LOCAL $p_Pdf = FileOpen($s_F,1) IF $p_Pdf = -1 THEN ;MsgBox(0,"error","Not Ready") RETURN 1 ELSE ;MsgBox(0,"ok","Ready") FileClose($p_Pdf) RETURN 0 ENDIF ENDFUNC Try this BBrain, Uses FileOpen for writing flag to temporarily check whether a file is currently being written to! Probably far more efficient methods on the forum though. muttley Link to comment Share on other sites More sharing options...
rover Posted July 18, 2008 Share Posted July 18, 2008 I'm watching a network folder for pdfs and then processing them but if I copy the pdf too soon all I get is a corrupt file. The pdf is being created by a scanner so I guess it makes the filename before the file is ready. How can I tell when it's safe? I tried checking the filesize every second until it has remained stable but I get the same result: Do $checkFileSize = FileGetSize ($newFile) Sleep(1000) $checkFileSize2 = FileGetSize ($newFile) Until $checkFileSize = $checkFileSize2 I think I also tried it with a bigger delay. Currently, I'm waiting 60s after the filename is seen before moving it, but that's hardly ideal. Has anyone any suggestions of attributes I can look at so I can get the file as soon as possible? scanner software has a file handle open to the pdf so that explains the file copy error check with this function in a loop until return is 0 Createfile() API example by Siao _FileInUse() I see fascists... Link to comment Share on other sites More sharing options...
BBrian Posted July 22, 2008 Author Share Posted July 22, 2008 _FileInUse($sFilename) worked great, though I had a gander at the other code too. Thanks guys. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now