faustf Posted May 15, 2018 Share Posted May 15, 2018 hi guys i have a script , it give me this Subscript used on non-accessible variable.: , but i dont understund why expandcollapse popup#AutoIt3Wrapper_Compression=3 #AutoIt3Wrapper_UseUpx=y #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator #AutoIt3Wrapper_Add_Constants=n #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Array.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include 'BackupFiles.au3' #include <WinAPIFiles.au3> #include <File.au3> _FindOldestFolder("C:\Users\SviluppoGest\Desktop\da-cancellare") Func _FindOldestFolder($Path) Local $FileList = _FileListToArray($Path, "*.*", 2) If @error = 1 Then MsgBox(0, "", "No Folders Found.") Exit EndIf If @error = 4 Then MsgBox(0, "", "No Files Found.") Exit EndIf Local $dLDateDay = _NowCalc() MsgBox(0, '', $dLDateDay) For $i = 0 To UBound($FileList) - 1 Local $aDateFolder = FileGetTime($Path & "\" & $FileList[$i], 1, 0) _ArrayDisplay($aDateFolder) MsgBox(0, '', $aDateFolder[0] & "/" & $aDateFolder[1] & "/" & $aDateFolder[2] & " " & $aDateFolder[3] & ":" & $aDateFolder[4] & ":" & $aDateFolder[5]) Next EndFunc ;==>_FindOldestFolder Link to comment Share on other sites More sharing options...
Andreik Posted May 15, 2018 Share Posted May 15, 2018 Because $FileList index 0 contains the number of indices in your array and later you start a loop from index 0 and $Path & "\" & $FileList[$i] is not a valid file/directory and your function set error flag. This is why you should check @error marco after you call a function. Link to comment Share on other sites More sharing options...
Zedna Posted May 15, 2018 Share Posted May 15, 2018 And here is the way how to check for @error after FileGetTime() expandcollapse popup#AutoIt3Wrapper_Compression=3 #AutoIt3Wrapper_UseUpx=y #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator #AutoIt3Wrapper_Add_Constants=n #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Array.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include 'BackupFiles.au3' #include <WinAPIFiles.au3> #include <File.au3> _FindOldestFolder("C:\Users\SviluppoGest\Desktop\da-cancellare") Func _FindOldestFolder($Path) Local $FileList = _FileListToArray($Path, "*.*", 2) If @error = 1 Then MsgBox(0, "", "No Folders Found.") Exit EndIf If @error = 4 Then MsgBox(0, "", "No Files Found.") Exit EndIf Local $dLDateDay = _NowCalc() MsgBox(0, '', $dLDateDay) For $i = 0 To UBound($FileList) - 1 Local $aDateFolder = FileGetTime($Path & "\" & $FileList[$i], 1, 0) If @error Then MsgBox(0, "FileGetTime Error", $Path & "\" & $FileList[$i]) Else _ArrayDisplay($aDateFolder) MsgBox(0, '', $aDateFolder[0] & "/" & $aDateFolder[1] & "/" & $aDateFolder[2] & " " & $aDateFolder[3] & ":" & $aDateFolder[4] & ":" & $aDateFolder[5]) EndIf Next EndFunc ;==>_FindOldestFolder Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
faustf Posted May 15, 2018 Author Share Posted May 15, 2018 (edited) but array display don't give me at row[0] the indices , but give me the year 2018 o_O and if i substitute MsgBox(0, '', $aDateFolder[0] & "/" & $aDateFolder[1] & "/" & $aDateFolder[2] & " " & $aDateFolder[3] & ":" & $aDateFolder[4] & ":" & $aDateFolder[5]) with this MsgBox(0, '', $aDateFolder[1] & "/" & $aDateFolder[1] & "/" & $aDateFolder[2] & " " & $aDateFolder[3] & ":" & $aDateFolder[4] & ":" & $aDateFolder[5]) i have the same error Edited May 15, 2018 by faustf Link to comment Share on other sites More sharing options...
faustf Posted May 15, 2018 Author Share Posted May 15, 2018 questions i modify the script in this mode and i work , but not understund why work and i think is a bug of autoit Func _FindOldestFolder($Path) Local $FileList = _FileListToArray($Path, "*.*", 2) If @error = 1 Then MsgBox(0, "", "No Folders Found.") Exit EndIf If @error = 4 Then MsgBox(0, "", "No Files Found.") Exit EndIf Local $dLDateDay = _NowCalc() MsgBox(0, '', $dLDateDay) For $i = 0 To UBound($FileList) - 1 Local $aDateFolder = FileGetTime($Path & "\" & $FileList[$i], 1, 0) If @error Then MsgBox(0, "FileGetTime Error", $Path & "\" & $FileList[$i]) Else _ArrayDisplay($aDateFolder) ;MsgBox(0, '',$aDateFolder[$i]) MsgBox(0, '', $aDateFolder[0] & "/" & $aDateFolder[1] & "/" & $aDateFolder[2] & " " & $aDateFolder[3] & ":" & $aDateFolder[4] & ":" & $aDateFolder[5]) EndIf Next EndFunc ;==>_FindOldestFolder when execute them , the program answer me with msgbox error and condition if @error then is verifyed , but in the same time go in else and execute also else , but not give me a error o_O , anyone can explain me ?? thankz Link to comment Share on other sites More sharing options...
Andreik Posted May 15, 2018 Share Posted May 15, 2018 I already pointed your mistake but seems you don't pay attention. _FileListToArray() always return an array, 0-based indexed, where index 0 contains the number of files (also the number of indices) in your array. And then you have this loop For $i = 0 To UBound($FileList) - 1 Local $aDateFolder = FileGetTime($Path & "\" & $FileList[$i], 1, 0) .... Next where you start your iteration from index 0 where you have the number of files in your array instead of the name of a valid file/directory. This is the reason why your FileGetTime() function returns nothing at first iteration and an error is thrown. To fix your problem just start your loop at index 1, something like: For $i = 1 To $FileList[0] ... Next Link to comment Share on other sites More sharing options...
faustf Posted May 15, 2018 Author Share Posted May 15, 2018 hi i have created a udf , i hope will be helpful at the comunity , best thankz at all for help and ofcourse if someone want modify , is welcome expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name ..........: _FindOldestFolder ; Description ...: _FindOldestFolder udf functions find a oldest or newer folder inside a folder ; Syntax ........: _FindOldestFolder($Path, $old_new = 0) ; Parameters ....: $Path - dirctory you wish find ; $old_new - choice if a program must find oldest "0" or yanger "1" folder ,default oldest ; Return values .: ; Author ........: Faustf ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _FindOldestFolder($Path, $old_new = 0) If $old_new = Default Then $old_new = 0 Local $FileList = _FileListToArray($Path, "*.*", 2) If @error = 1 Then MsgBox(0, "", "No Folders Found.") Exit EndIf If @error = 4 Then MsgBox(0, "", "No Files Found.") Exit EndIf Local $aLDateDiff[($FileList[0] + 1)] For $i = 0 To UBound($FileList) - 1 Local $aDateFolder = FileGetTime($Path & "\" & $FileList[$i], 1, 0) If @error Then ;MsgBox(0, "FileGetTime Error", $Path & "\" & $FileList[$i]) Else Local $dLOldDate = ($aDateFolder[0] & "/" & $aDateFolder[1] & "/" & $aDateFolder[2] & " " & $aDateFolder[3] & ":" & $aDateFolder[4] & ":" & $aDateFolder[5]) $aLDateDiff[$i] = _DateDiff("s", $dLOldDate, _NowCalc()) EndIf Next If $old_new = 0 Then Return $FileList[_ArrayMaxIndex($aLDateDiff)] Else Return $FileList[_ArrayMinIndex($aLDateDiff)] EndIf EndFunc ;==>_FindOldestFolder Earthshine 1 Link to comment Share on other sites More sharing options...
Earthshine Posted May 15, 2018 Share Posted May 15, 2018 (edited) sweet. You could probably start a new thread in the AutoIT Example Forum. My point being, people are probably going to not associate this thread title with a UDF that finds the oldest folder. I will test it. Nice work BTW. Edited May 15, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 15, 2018 Moderators Share Posted May 15, 2018 (edited) Agreed. @faustf if the script actually works, it is probably better to add it to the Examples forum (more of an addition to the snippets thread than a full UDF IMO), rather than posting it in a topic where it looks like you did not know what you were doing. Edited May 15, 2018 by JLogan3o13 Earthshine 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
faustf Posted May 15, 2018 Author Share Posted May 15, 2018 ok i will do thankz again Link to comment Share on other sites More sharing options...
Andreik Posted May 15, 2018 Share Posted May 15, 2018 How could you call this an UDF when you comment the part of the function that tells you're not doing it right? Link to comment Share on other sites More sharing options...
faustf Posted May 15, 2018 Author Share Posted May 15, 2018 yea have right , sorry i copyed a udf wrong expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name ..........: _FindOldestFolder ; Description ...: _FindOldestFolder udf functions find a oldest or newer folder inside a folder ; Syntax ........: _FindOldestFolder($Path, $old_new = 0) ; Parameters ....: $Path - dirctory you wish find ; $old_new - choice if a program must find oldest "0" or yanger "1" folder ,default oldest ; Return values .: ; Author ........: Faustf ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _FindOldestFolder($Path, $old_new = 0) If $old_new = Default Then $old_new = 0 Local $FileList = _FileListToArray($Path, "*.*", 2) If @error = 1 Then MsgBox(0, "", "No Folders Found.") Exit EndIf If @error = 4 Then MsgBox(0, "", "No Files Found.") Exit EndIf Local $aLDateDiff[($FileList[0] + 1)] For $i = 1 To UBound($FileList) - 1 Local $aDateFolder = FileGetTime($Path & "\" & $FileList[$i], 1, 0) If @error Then ;MsgBox(0, "FileGetTime Error", $Path & "\" & $FileList[$i]) Return 0 Else Local $dLOldDate = ($aDateFolder[0] & "/" & $aDateFolder[1] & "/" & $aDateFolder[2] & " " & $aDateFolder[3] & ":" & $aDateFolder[4] & ":" & $aDateFolder[5]) $aLDateDiff[$i] = _DateDiff("s", $dLOldDate, _NowCalc()) EndIf Next If $old_new = 0 Then Return $FileList[_ArrayMaxIndex($aLDateDiff)] Else Return $FileList[_ArrayMinIndex($aLDateDiff)] EndIf EndFunc ;==>_FindOldestFolder Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 15, 2018 Moderators Share Posted May 15, 2018 Still think this is more a snippet than a UDF, and if you do post in Examples, don't be surprised if you receive some critique. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! 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