skysel Posted December 2, 2008 Share Posted December 2, 2008 Good morning to all, I've looked around the forum but couldn't find anything related, so I'm asking for help here.. What happens in my script is, that when files are copied from network location, it appears that some files cannot be copied because they are locked by some proccess. How can I skip those files which are locked at the moment of copying? This is the script.. expandcollapse popup#Include <File.au3> #Include <String.au3> #Include <Array.au3> #Include <Zip.au3> ;Ay-Aic01 Dim $filename = "aic01." & @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN Dim $myfile = StringSplit("\\Ay-aic01\logs\ADU_Voice1.log,\\Ay-aic01\logs\Alarm.log,\\Ay-aic01\logs\DataServerMSSQL_Default.log,\\Ay-aic01\logs\DataServerMSSQL_Email.log,\\Ay-aic01\logs\DataServerMSSQL_Voice1.log,\\Ay-aic01\logs\DataServerMSSQL_Voice1_Helper.log,\\Ay-aic01\logs\EDU_Email_Helper.log,\\Ay-aic01\logs\EDU_Voice1_Helper.log,\\Ay-aic01\logs\Report_Email_Helper.log,\\Ay-aic01\logs\Report_Voice1_Helper.log,\\Ay-aic01\logs\TSDefinity_Voice1.log,\\Ay-aic01\logs\TSQS_Voice1.log,\\Ay-aic01\logs\VOX_Voice1.log,\\Ay-aic01\logs\WorkFlow_Email.log,\\Ay-aic01\logs\WorkFlow_User1.log,\\Ay-aic01\logs\WorkFlow_Voice1.log",",") ;Ay-Aic02 Dim $filename2 = "aic02." & @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN Dim $myfile2 = StringSplit("\\Ay-aic02\logs\ADU_Voice2.log,\\Ay-aic02\logs\Alarm_Core2.log,\\Ay-aic02\logs\DataServerMSSQL_Core2.log,\\Ay-aic02\logs\DataServerMSSQL_Voice2.log,\\Ay-aic02\logs\DataServerMSSQL_Voice2_Helper.log,\\Ay-aic02\logs\EDU_Voice2_Helper.log,\\Ay-aic02\logs\Report_Voice2_Helper.log,\\Ay-aic02\logs\TSDefinity_Voice2.log,\\Ay-aic02\logs\TSQS_Voice2.log,\\Ay-aic02\logs\VOX_Voice2.log,\\Ay-aic02\logs\WorkFlow_User2.log,\\Ay-aic02\logs\WorkFlow_Voice2.log",",") Dim $Zip DirCreate("C:\Avayalogs") ;Ay-Aic01 DirCreate("C:\ay-aic01") for $n =1 to UBound($myfile) -1 FileCopy($myfile[$n],"C:\ay-aic01") Next $Zip = _Zip_Create("C:\Avayalogs\" & $filename & ".zip") _Zip_AddFolder($Zip, "C:\ay-aic01",4) FileDelete("C:\ay-aic01\*.log") DirRemove("C:\ay-aic01") ;Ay-Aic02 DirCreate("C:\ay-aic02") for $n =1 to UBound($myfile2) -1 FileCopy($myfile2[$n],"C:\ay-aic02") Next $Zip = _Zip_Create("C:\Avayalogs\" & $filename2 & ".zip") _Zip_AddFolder($Zip, "C:\ay-aic02",4) FileDelete("C:\ay-aic02\*.log") DirRemove("C:\ay-aic02") Link to comment Share on other sites More sharing options...
Pain Posted December 2, 2008 Share Posted December 2, 2008 Take a look at rovers _FileInUse function here.http://www.autoitscript.com/forum/index.php?showtopic=79251 Link to comment Share on other sites More sharing options...
skysel Posted December 3, 2008 Author Share Posted December 3, 2008 (edited) good morning again so based on the link you provided, I modified script like this: expandcollapse popup#Include <File.au3> #Include <String.au3> #Include <Array.au3> #Include <Zip.au3> ;Ay-Aic01 Dim $filename = "aic01." & @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN Dim $myfile = StringSplit("\\Ay-aic01\logs\ADU_Voice1.log,\\Ay-aic01\logs\Alarm.log,\\Ay-aic01\logs\DataServerMSSQL_Default.log,\\Ay-aic01\logs\DataServerMSSQL_Email.log,\\Ay-aic01\logs\DataServerMSSQL_Voice1.log,\\Ay-aic01\logs\DataServerMSSQL_Voice1_Helper.log,\\Ay-aic01\logs\EDU_Email_Helper.log,\\Ay-aic01\logs\EDU_Voice1_Helper.log,\\Ay-aic01\logs\Report_Email_Helper.log,\\Ay-aic01\logs\Report_Voice1_Helper.log,\\Ay-aic01\logs\TSDefinity_Voice1.log,\\Ay-aic01\logs\TSQS_Voice1.log,\\Ay-aic01\logs\VOX_Voice1.log,\\Ay-aic01\logs\WorkFlow_Email.log,\\Ay-aic01\logs\WorkFlow_User1.log,\\Ay-aic01\logs\WorkFlow_Voice1.log",",") ;Ay-Aic02 Dim $filename2 = "aic02." & @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN Dim $myfile2 = StringSplit("\\Ay-aic02\logs\ADU_Voice2.log,\\Ay-aic02\logs\Alarm_Core2.log,\\Ay-aic02\logs\DataServerMSSQL_Core2.log,\\Ay-aic02\logs\DataServerMSSQL_Voice2.log,\\Ay-aic02\logs\DataServerMSSQL_Voice2_Helper.log,\\Ay-aic02\logs\EDU_Voice2_Helper.log,\\Ay-aic02\logs\Report_Voice2_Helper.log,\\Ay-aic02\logs\TSDefinity_Voice2.log,\\Ay-aic02\logs\TSQS_Voice2.log,\\Ay-aic02\logs\VOX_Voice2.log,\\Ay-aic02\logs\WorkFlow_User2.log,\\Ay-aic02\logs\WorkFlow_Voice2.log",",") ;zip Dim $Zip ;FileInUse Local $file = $myfile, $myfile2 Local $bFileOpen While 1 Sleep(10) for $n =1 to UBound($file) -1 Next $bFileOpen = _FileInUse($file[$n], 1) If $bFileOpen = -1 And $bFileOpen = 1 Then Exit WEnd ;Script start DirCreate("C:\Avayalogs") ;part 1 DirCreate("C:\ay-aic01") for $n =1 to UBound($myfile) -1 FileCopy($myfile[$n],"C:\ay-aic01") Next $Zip = _Zip_Create("C:\Avayalogs\" & $filename & ".zip") _Zip_AddFolder($Zip, "C:\ay-aic01",4) FileDelete("C:\ay-aic01\*.log") DirRemove("C:\ay-aic01") ;part 2 DirCreate("C:\ay-aic02") for $n =1 to UBound($myfile2) -1 FileCopy($myfile2[$n],"C:\ay-aic02") Next $Zip = _Zip_Create("C:\Avayalogs\" & $filename2 & ".zip") _Zip_AddFolder($Zip, "C:\ay-aic02",4) FileDelete("C:\ay-aic02\*.log") DirRemove("C:\ay-aic02") ;from this post: ;Need help with copy verification ;http://www.autoitscript.com/forum/index.php?showtopic=53994 ;=============================================================================== ; ; Function Name: _FileInUse() ; Description: Checks if file is in use ; Syntax.........: _FileInUse($sFilename, $iAccess = 1) ; Parameter(s): $sFilename = File name ; Parameter(s): $iAccess = 0 = GENERIC_READ - other apps can have file open in readonly mode ; $iAccess = 1 = GENERIC_READ|GENERIC_WRITE - exclusive access to file, ; fails if file open in readonly mode by app ; Return Value(s): 1 - file in use (@error contains system error code) ; 0 - file not in use ; -1 dllcall error (@error contains dllcall error code) ; Author: Siao ; Modified rover - added some additional error handling, access mode ; Remarks _WinAPI_CreateFile() WinAPI.au3 ;=============================================================================== Func _FileInUse($sFilename, $iAccess = 0) Local $aRet, $hFile, $iError, $iDA Local Const $GENERIC_WRITE = 0x40000000 Local Const $GENERIC_READ = 0x80000000 Local Const $FILE_ATTRIBUTE_NORMAL = 0x80 Local Const $OPEN_EXISTING = 3 $iDA = $GENERIC_READ If BitAND($iAccess, 1) <> 0 Then $iDA = BitOR($GENERIC_READ, $GENERIC_WRITE) $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sFilename, _ ;lpFileName "dword", $iDA, _ ;dwDesiredAccess "dword", 0x00000000, _ ;dwShareMode = DO NOT SHARE "dword", 0x00000000, _ ;lpSecurityAttributes = NULL "dword", $OPEN_EXISTING, _ ;dwCreationDisposition = OPEN_EXISTING "dword", $FILE_ATTRIBUTE_NORMAL, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL "hwnd", 0) ;hTemplateFile = NULL $iError = @error If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, -1) $hFile = $aRet[0] If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1 $aRet = DllCall("Kernel32.dll", "int", "GetLastError") ;ERROR_SHARING_VIOLATION = 32 0x20 ;The process cannot access the file because it is being used by another process. If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, 1) Return SetError($aRet[0], 0, 1) Else ;close file handle DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return SetError(@error, 0, 0) EndIf EndFunc Is this ok? The script should exit if it detects file in use. I dont want any verbose messages, thats why I removed error checking. Edited December 3, 2008 by skysel Link to comment Share on other sites More sharing options...
Pain Posted December 3, 2008 Share Posted December 3, 2008 Well it would be better to use ContinueLoop (skip that file and take next) instead of Exit the whole program if a file is in use. Link to comment Share on other sites More sharing options...
skysel Posted December 4, 2008 Author Share Posted December 4, 2008 Meh, the script doesn't work anyways, it says: C:\Users\....\Desktop\Scripts\AvayaZipLog.au3 (73) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $bFileOpen = _FileInUse($file[$n], 1) $bFileOpen = _FileInUse(^ ERROR further help please.. Link to comment Share on other sites More sharing options...
skysel Posted December 5, 2008 Author Share Posted December 5, 2008 bump..... Link to comment Share on other sites More sharing options...
KaFu Posted December 5, 2008 Share Posted December 5, 2008 (edited) Looks like your $file variable is screwed.... I took the script from your first post (hope that it works) and added the marked code... expandcollapse popup#Include <File.au3> #Include <String.au3> #Include <Array.au3> #Include <Zip.au3> ;Ay-Aic01 Dim $filename = "aic01." & @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN Dim $myfile = StringSplit("\\Ay-aic01\logs\ADU_Voice1.log,\\Ay-aic01\logs\Alarm.log,\\Ay-aic01\logs\DataServerMSSQL_Default.log,\\Ay-aic01\logs\DataServerMSSQL_Email.log,\\Ay-aic01\logs\DataServerMSSQL_Voice1.log,\\Ay-aic01\logs\DataServerMSSQL_Voice1_Helper.log,\\Ay-aic01\logs\EDU_Email_Helper.log,\\Ay-aic01\logs\EDU_Voice1_Helper.log,\\Ay-aic01\logs\Report_Email_Helper.log,\\Ay-aic01\logs\Report_Voice1_Helper.log,\\Ay-aic01\logs\TSDefinity_Voice1.log,\\Ay-aic01\logs\TSQS_Voice1.log,\\Ay-aic01\logs\VOX_Voice1.log,\\Ay-aic01\logs\WorkFlow_Email.log,\\Ay-aic01\logs\WorkFlow_User1.log,\\Ay-aic01\logs\WorkFlow_Voice1.log",",") ;Ay-Aic02 Dim $filename2 = "aic02." & @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN Dim $myfile2 = StringSplit("\\Ay-aic02\logs\ADU_Voice2.log,\\Ay-aic02\logs\Alarm_Core2.log,\\Ay-aic02\logs\DataServerMSSQL_Core2.log,\\Ay-aic02\logs\DataServerMSSQL_Voice2.log,\\Ay-aic02\logs\DataServerMSSQL_Voice2_Helper.log,\\Ay-aic02\logs\EDU_Voice2_Helper.log,\\Ay-aic02\logs\Report_Voice2_Helper.log,\\Ay-aic02\logs\TSDefinity_Voice2.log,\\Ay-aic02\logs\TSQS_Voice2.log,\\Ay-aic02\logs\VOX_Voice2.log,\\Ay-aic02\logs\WorkFlow_User2.log,\\Ay-aic02\logs\WorkFlow_Voice2.log",",") Dim $Zip DirCreate("C:\Avayalogs") ;Ay-Aic01 DirCreate("C:\ay-aic01") for $n =1 to UBound($myfile) -1 if _FileInUse($myfile[$n], 1) then continueloop ; ADDED FileCopy($myfile[$n],"C:\ay-aic01") Next $Zip = _Zip_Create("C:\Avayalogs\" & $filename & ".zip") _Zip_AddFolder($Zip, "C:\ay-aic01",4) FileDelete("C:\ay-aic01\*.log") DirRemove("C:\ay-aic01") ;Ay-Aic02 DirCreate("C:\ay-aic02") for $n =1 to UBound($myfile2) -1 if _FileInUse($myfile2[$n], 1) then continueloop ; ADDED FileCopy($myfile2[$n],"C:\ay-aic02") Next $Zip = _Zip_Create("C:\Avayalogs\" & $filename2 & ".zip") _Zip_AddFolder($Zip, "C:\ay-aic02",4) FileDelete("C:\ay-aic02\*.log") DirRemove("C:\ay-aic02") ;from this post: ;Need help with copy verification ;http://www.autoitscript.com/forum/index.php?showtopic=53994 ;=============================================================================== ; ; Function Name: _FileInUse() ; Description: Checks if file is in use ; Syntax.........: _FileInUse($sFilename, $iAccess = 1) ; Parameter(s): $sFilename = File name ; Parameter(s): $iAccess = 0 = GENERIC_READ - other apps can have file open in readonly mode ; $iAccess = 1 = GENERIC_READ|GENERIC_WRITE - exclusive access to file, ; fails if file open in readonly mode by app ; Return Value(s): 1 - file in use (@error contains system error code) ; 0 - file not in use ; -1 dllcall error (@error contains dllcall error code) ; Author: Siao ; Modified rover - added some additional error handling, access mode ; Remarks _WinAPI_CreateFile() WinAPI.au3 ;=============================================================================== Func _FileInUse($sFilename, $iAccess = 0) Local $aRet, $hFile, $iError, $iDA Local Const $GENERIC_WRITE = 0x40000000 Local Const $GENERIC_READ = 0x80000000 Local Const $FILE_ATTRIBUTE_NORMAL = 0x80 Local Const $OPEN_EXISTING = 3 $iDA = $GENERIC_READ If BitAND($iAccess, 1) <> 0 Then $iDA = BitOR($GENERIC_READ, $GENERIC_WRITE) $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sFilename, _ ;lpFileName "dword", $iDA, _ ;dwDesiredAccess "dword", 0x00000000, _ ;dwShareMode = DO NOT SHARE "dword", 0x00000000, _ ;lpSecurityAttributes = NULL "dword", $OPEN_EXISTING, _ ;dwCreationDisposition = OPEN_EXISTING "dword", $FILE_ATTRIBUTE_NORMAL, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL "hwnd", 0) ;hTemplateFile = NULL $iError = @error If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, -1) $hFile = $aRet[0] If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1 $aRet = DllCall("Kernel32.dll", "int", "GetLastError") ;ERROR_SHARING_VIOLATION = 32 0x20 ;The process cannot access the file because it is being used by another process. If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, 1) Return SetError($aRet[0], 0, 1) Else ;close file handle DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return SetError(@error, 0, 0) EndIf EndFunc Edited December 5, 2008 by KaFu  OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
skysel Posted December 5, 2008 Author Share Posted December 5, 2008 Looks like your $file variable is screwed.... I took the script from your first post (hope that it works) and added the marked code... expandcollapse popup#Include <File.au3> #Include <String.au3> #Include <Array.au3> #Include <Zip.au3> ;Ay-Aic01 Dim $filename = "aic01." & @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN Dim $myfile = StringSplit("\\Ay-aic01\logs\ADU_Voice1.log,\\Ay-aic01\logs\Alarm.log,\\Ay-aic01\logs\DataServerMSSQL_Default.log,\\Ay-aic01\logs\DataServerMSSQL_Email.log,\\Ay-aic01\logs\DataServerMSSQL_Voice1.log,\\Ay-aic01\logs\DataServerMSSQL_Voice1_Helper.log,\\Ay-aic01\logs\EDU_Email_Helper.log,\\Ay-aic01\logs\EDU_Voice1_Helper.log,\\Ay-aic01\logs\Report_Email_Helper.log,\\Ay-aic01\logs\Report_Voice1_Helper.log,\\Ay-aic01\logs\TSDefinity_Voice1.log,\\Ay-aic01\logs\TSQS_Voice1.log,\\Ay-aic01\logs\VOX_Voice1.log,\\Ay-aic01\logs\WorkFlow_Email.log,\\Ay-aic01\logs\WorkFlow_User1.log,\\Ay-aic01\logs\WorkFlow_Voice1.log",",") ;Ay-Aic02 Dim $filename2 = "aic02." & @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN Dim $myfile2 = StringSplit("\\Ay-aic02\logs\ADU_Voice2.log,\\Ay-aic02\logs\Alarm_Core2.log,\\Ay-aic02\logs\DataServerMSSQL_Core2.log,\\Ay-aic02\logs\DataServerMSSQL_Voice2.log,\\Ay-aic02\logs\DataServerMSSQL_Voice2_Helper.log,\\Ay-aic02\logs\EDU_Voice2_Helper.log,\\Ay-aic02\logs\Report_Voice2_Helper.log,\\Ay-aic02\logs\TSDefinity_Voice2.log,\\Ay-aic02\logs\TSQS_Voice2.log,\\Ay-aic02\logs\VOX_Voice2.log,\\Ay-aic02\logs\WorkFlow_User2.log,\\Ay-aic02\logs\WorkFlow_Voice2.log",",") Dim $Zip DirCreate("C:\Avayalogs") ;Ay-Aic01 DirCreate("C:\ay-aic01") for $n =1 to UBound($myfile) -1 if _FileInUse($myfile[$n], 1) then continueloop ; ADDED FileCopy($myfile[$n],"C:\ay-aic01") Next $Zip = _Zip_Create("C:\Avayalogs\" & $filename & ".zip") _Zip_AddFolder($Zip, "C:\ay-aic01",4) FileDelete("C:\ay-aic01\*.log") DirRemove("C:\ay-aic01") ;Ay-Aic02 DirCreate("C:\ay-aic02") for $n =1 to UBound($myfile2) -1 if _FileInUse($myfile2[$n], 1) then continueloop ; ADDED FileCopy($myfile2[$n],"C:\ay-aic02") Next $Zip = _Zip_Create("C:\Avayalogs\" & $filename2 & ".zip") _Zip_AddFolder($Zip, "C:\ay-aic02",4) FileDelete("C:\ay-aic02\*.log") DirRemove("C:\ay-aic02") ;from this post: ;Need help with copy verification ;http://www.autoitscript.com/forum/index.php?showtopic=53994 ;=============================================================================== ; ; Function Name: _FileInUse() ; Description: Checks if file is in use ; Syntax.........: _FileInUse($sFilename, $iAccess = 1) ; Parameter(s): $sFilename = File name ; Parameter(s): $iAccess = 0 = GENERIC_READ - other apps can have file open in readonly mode ; $iAccess = 1 = GENERIC_READ|GENERIC_WRITE - exclusive access to file, ; fails if file open in readonly mode by app ; Return Value(s): 1 - file in use (@error contains system error code) ; 0 - file not in use ; -1 dllcall error (@error contains dllcall error code) ; Author: Siao ; Modified rover - added some additional error handling, access mode ; Remarks _WinAPI_CreateFile() WinAPI.au3 ;=============================================================================== Func _FileInUse($sFilename, $iAccess = 0) Local $aRet, $hFile, $iError, $iDA Local Const $GENERIC_WRITE = 0x40000000 Local Const $GENERIC_READ = 0x80000000 Local Const $FILE_ATTRIBUTE_NORMAL = 0x80 Local Const $OPEN_EXISTING = 3 $iDA = $GENERIC_READ If BitAND($iAccess, 1) <> 0 Then $iDA = BitOR($GENERIC_READ, $GENERIC_WRITE) $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sFilename, _ ;lpFileName "dword", $iDA, _ ;dwDesiredAccess "dword", 0x00000000, _ ;dwShareMode = DO NOT SHARE "dword", 0x00000000, _ ;lpSecurityAttributes = NULL "dword", $OPEN_EXISTING, _ ;dwCreationDisposition = OPEN_EXISTING "dword", $FILE_ATTRIBUTE_NORMAL, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL "hwnd", 0) ;hTemplateFile = NULL $iError = @error If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, -1) $hFile = $aRet[0] If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1 $aRet = DllCall("Kernel32.dll", "int", "GetLastError") ;ERROR_SHARING_VIOLATION = 32 0x20 ;The process cannot access the file because it is being used by another process. If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, 1) Return SetError($aRet[0], 0, 1) Else ;close file handle DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return SetError(@error, 0, 0) EndIf EndFunc Now it reports that folder c:\ay-aic01 is empty so it cannot create any zip archive.. :s Link to comment Share on other sites More sharing options...
KaFu Posted December 5, 2008 Share Posted December 5, 2008 _FileInUse($myfile[$n],0) and _FileInUse($myfile2[$n],0) ? Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
skysel Posted December 5, 2008 Author Share Posted December 5, 2008 _FileInUse($myfile[$n],0) and _FileInUse($myfile2[$n],0) ? same .... Link to comment Share on other sites More sharing options...
KaFu Posted December 5, 2008 Share Posted December 5, 2008 I see... my guess is, that _FileInUse() only works for local processes and you're working on a network drive... what are the error codes, if you call them directly after the _FileInUse()? _FileInUse($myfile[$n],0) MsgBox(0,"",@error) Took a look into the UDF's... maybe _Net_Share_FileGetInfo() is a better way to go? Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
skysel Posted December 5, 2008 Author Share Posted December 5, 2008 hmm...if _FileInUse($myfile[$n], 0) And MsgBox(0,"",@error) then continueloop; ADDEDI modified this line so error appears. But there is no error. For each file it returns "0", which means:Return Value(s): 1 - file in use (@error contains system error code) 0 - file not in useSo I assume this part of script is OK. Must be something wrong with FileCopy then... Link to comment Share on other sites More sharing options...
KaFu Posted December 5, 2008 Share Posted December 5, 2008 Guess the _FileInUse() is only valid for local operations... maybe _Net_Share_FileGetInfo() will help. Maybe also take a look at the FileCopy() syntax by adding an msgbox msgbox(0,"",$myfile[$n] & @crlf & ,"C:\ay-aic01") Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
skysel Posted December 5, 2008 Author Share Posted December 5, 2008 That is kind of invalid function. Atleast syntax check fails. Unless I failed to put it in the script correctly Link to comment Share on other sites More sharing options...
KaFu Posted December 5, 2008 Share Posted December 5, 2008 Right, happens if you try to code in "Fast Reply" msgbox(0,"",$myfile[$n] & @crlf & "C:\ay-aic01") Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
skysel Posted December 5, 2008 Author Share Posted December 5, 2008 Right, happens if you try to code in "Fast Reply" msgbox(0,"",$myfile[$n] & @crlf & "C:\ay-aic01") Im not sure where to put this msgbox, as filecopy syntax doesnt support inside commands? I tried putting it before filecopy, and after filecopy. Both resulted in same error as before (no files can be found in the directory, so therefor archive cannot be created..) Link to comment Share on other sites More sharing options...
KaFu Posted December 5, 2008 Share Posted December 5, 2008 hmmm, tested the following on our server here... expandcollapse popup#Include <File.au3> #Include <String.au3> #Include <Array.au3> #Include <Zip.au3> ;Ay-Aic01 Dim $filename = "aic01." & @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN Dim $myfile = StringSplit("\\server\dir\test.gif,\\server\dir\test2.gif,\\server\dir\test.xls,",",") Dim $Zip DirCreate("C:\Avayalogs") ;Ay-Aic01 DirCreate("C:\ay-aic01") for $n =1 to UBound($myfile) -1 msgbox(0,"",$myfile[$n] & @crlf & "C:\ay-aic01") if _FileInUse($myfile[$n], 0) then MsgBox(0,"",@error) ;continueloop ; ADDED EndIf FileCopy($myfile[$n],"C:\ay-aic01") Next $Zip = _Zip_Create("C:\Avayalogs\" & $filename & ".zip") _Zip_AddFolder($Zip, "C:\ay-aic01",4) FileDelete("C:\ay-aic01\*.log") DirRemove("C:\ay-aic01") ;from this post: ;Need help with copy verification ;http://www.autoitscript.com/forum/index.php?showtopic=53994 ;=============================================================================== ; ; Function Name: _FileInUse() ; Description: Checks if file is in use ; Syntax.........: _FileInUse($sFilename, $iAccess = 1) ; Parameter(s): $sFilename = File name ; Parameter(s): $iAccess = 0 = GENERIC_READ - other apps can have file open in readonly mode ; $iAccess = 1 = GENERIC_READ|GENERIC_WRITE - exclusive access to file, ; fails if file open in readonly mode by app ; Return Value(s): 1 - file in use (@error contains system error code) ; 0 - file not in use ; -1 dllcall error (@error contains dllcall error code) ; Author: Siao ; Modified rover - added some additional error handling, access mode ; Remarks _WinAPI_CreateFile() WinAPI.au3 ;=============================================================================== Func _FileInUse($sFilename, $iAccess = 0) Local $aRet, $hFile, $iError, $iDA Local Const $GENERIC_WRITE = 0x40000000 Local Const $GENERIC_READ = 0x80000000 Local Const $FILE_ATTRIBUTE_NORMAL = 0x80 Local Const $OPEN_EXISTING = 3 $iDA = $GENERIC_READ If BitAND($iAccess, 1) <> 0 Then $iDA = BitOR($GENERIC_READ, $GENERIC_WRITE) $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sFilename, _ ;lpFileName "dword", $iDA, _ ;dwDesiredAccess "dword", 0x00000000, _ ;dwShareMode = DO NOT SHARE "dword", 0x00000000, _ ;lpSecurityAttributes = NULL "dword", $OPEN_EXISTING, _ ;dwCreationDisposition = OPEN_EXISTING "dword", $FILE_ATTRIBUTE_NORMAL, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL "hwnd", 0) ;hTemplateFile = NULL $iError = @error If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, -1) $hFile = $aRet[0] If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1 $aRet = DllCall("Kernel32.dll", "int", "GetLastError") ;ERROR_SHARING_VIOLATION = 32 0x20 ;The process cannot access the file because it is being used by another process. If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, 1) Return SetError($aRet[0], 0, 1) Else ;close file handle DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return SetError(@error, 0, 0) EndIf EndFunc The two gifs were not open and copied sucessfully, the xls i opend manually and the FileCopy was skipped due to the _FileInUse(). A zip containing the two gifs was created successfully... When i commented the _FileInUse() part, the open xls was copied sucessfully too. So here some more guesses / questions... - re-check the syntax of the target file-location (try to open them by copy&paste the address in the explorer address bar)... - all of the files you want to copy ARE open and thus the copying process is skipped with reason... - is it possible to manually copy the files? - what is the EXACT failure behavior? Does the script finish? Throw error messages? Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
KaFu Posted December 5, 2008 Share Posted December 5, 2008 OR alternative remove the _FileInUse() function and replace FileCopy() with RunWait(@ComSpec & " /c " & 'copy "' & $myfile[$n] &'" "C:\ay-aic01"', "", @SW_HIDE); Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
skysel Posted December 5, 2008 Author Share Posted December 5, 2008 OR alternative remove the _FileInUse() function and replace FileCopy() with RunWait(@ComSpec & " /c " & 'copy "' & $myfile[$n] &'" "C:\ay-aic01"', "", @SW_HIDE); Ah, excelent workaround. I will try it on monday and will let you know how it goes. As for _FileInUse, the script only reported that there are no files in directory which was supposed to be zipped. So there must have been problem with FileCopy - but what - is beyond my knowledge. Copy command automaticly skips the file if it is in use so thats the perfect solution for me. It doesnt pause the script - meanwhile with FileCopy and without FileInUse the script just paused for unknown reason, thats why I wanted FileInUse on first place. Hope it makes sense Thanks for the help and I'll let you know how it goes! Link to comment Share on other sites More sharing options...
skysel Posted December 8, 2008 Author Share Posted December 8, 2008 Hmm, now with only copy statement in script, it generates error "Object referenced outside a "With" statement"... So is there missing a WITH statement somewhere? 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