Stalker0 Posted September 25, 2007 Share Posted September 25, 2007 (edited) After three hours I'm really stuck on this one guys, any help people could provide would be great. What I'm doing is opening up a lotus notes program, making some alterations and saving the file. Lotus does the copying within the program, it doesn't provide any notification when the copying is finished, but I need to know when the copying is done before the script can continue. I'm using the following code right now: Do $attribute = FileGetTime($FiletoCheck,0,1) SLEEP(3000) $attributenew = FileGetTime($FiletoCheck, 0, 1) UNTIL $attribute = $attributenew Its working right now, but if I drop the sleep timer down to 2000 sometimes it believes the file is finished copying before it actually is. I'm worried that with a very large file the timer may not be enough, and its just not an elegant way to do this. I have tried comparing the file accessed time (which doesn't work because the script itself changes it), the file size (doesn't work, apprarantely the programs sets up the full file skeleton before it fills in all the data), and the file atrribute (always comes back as archive from start to finish). Does anyone know a more elegant and reliable way to do this? Also one more note, lotus must do the copying, as its making special alterations to the file I do not know how to do with another program. So I can't just outsource the copying to another program. Edited September 25, 2007 by Stalker0 Link to comment Share on other sites More sharing options...
Stalker0 Posted September 26, 2007 Author Share Posted September 26, 2007 Any ideas? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 26, 2007 Moderators Share Posted September 26, 2007 Does lotus exit and close it's process after it is done doing what you want? Could always do a:ProcessWaitClose('lotus') Is it always writing to the file (meaning does it have the file open the whole time)... could always do a FileOpen() and check for @error then I suppose. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Stalker0 Posted September 26, 2007 Author Share Posted September 26, 2007 Lotus stays open when the file is finished so that idea is out. Is there a way to generate the open file error without actually opening the file again? That idea might just work. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 26, 2007 Moderators Share Posted September 26, 2007 Is there a way to generate the open file error without actually opening the file again?How about a tall glass of confusion with that as well ... Seriously, the only way it's going to generate an error is if it's already open. While _IsFileInUse($sPath) Sleep(500) WEnd Func _IsFileInUse($sPath);Return 0 if not in use Local $nError, $hOpen = FileOpen($sPath, 1) $nError = @error FileClose($hOpen) Return $nError EndFuncThis isn't tested, but let me know if it works or not. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Siao Posted September 26, 2007 Share Posted September 26, 2007 (edited) You can DllCall OpenFile API with OF_SHARE_EXCLUSIVE attribute set, which would throw an error if the file is already open for reading/writing.While it probably would be more reliable than the method you currently use, it can hardly be called elegant AutoIt's FileOpen/FileClose does not work for this purpose. Edited September 26, 2007 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
Stalker0 Posted September 27, 2007 Author Share Posted September 27, 2007 You can DllCall OpenFile API with OF_SHARE_EXCLUSIVE attribute set, which would throw an error if the file is already open for reading/writing.While it probably would be more reliable than the method you currently use, it can hardly be called elegant AutoIt's FileOpen/FileClose does not work for this purpose.Could you show me some code samples, I'm not sure how to set this one up. Link to comment Share on other sites More sharing options...
Siao Posted September 27, 2007 Share Posted September 27, 2007 (edited) Forum is full of examples and UDFs of how to use DllCall, using Windows API too. Anyway, here you go... expandcollapse popup$file = "FileInUseTestfile.txt" $h = FileOpen($file, 1) $x = _FileInUse($file) MsgBox(0, "_FileInUse() example", "File "& $file & @CRLF & "Return= " & $x & " (Error = " & @error & ")") FileClose($h) $x = _FileInUse($file) MsgBox(0, "_FileInUse() example", "File "& $file & @CRLF & "Return= " & $x & " (Error = " & @error & ")") FileDelete($file) ;=============================================================================== ; ; Function Name: _FileInUse() ; Description: Checks if file is in use ; Parameter(s): $sFilename = File name ; Return Value(s): 1 - file in use (@error contains system error code) ; 0 - file not in use ; ;=============================================================================== Func _FileInUse($sFilename) Local $aRet, $hFile $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sFilename, _ ;lpFileName "dword", 0x80000000, _ ;dwDesiredAccess = GENERIC_READ "dword", 0, _ ;dwShareMode = DO NOT SHARE "dword", 0, _ ;lpSecurityAttributes = NULL "dword", 3, _ ;dwCreationDisposition = OPEN_EXISTING "dword", 128, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL "hwnd", 0) ;hTemplateFile = NULL $hFile = $aRet[0] If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1 $aRet = DllCall("Kernel32.dll", "int", "GetLastError") SetError($aRet[0]) Return 1 Else ;close file handle DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return 0 EndIf EndFunc Edited September 27, 2007 by Siao ss26 and gcue 2 "be smart, drink your wine" 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