faustf Posted May 15, 2018 Share Posted May 15, 2018 hi guys 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 .: if have error return 0 if nt have error return path+name folder ; 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 Earthshine 1 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 15, 2018 Moderators Share Posted May 15, 2018 So, if someone uses your function as part of a larger script, you attempt to create the array of folders and if it can't, instead of returning from the function it does a full Exit, closing the whole script? "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 yea is not perfect udf bu is perfectible , thankz fo sudgest Link to comment Share on other sites More sharing options...
faustf Posted May 15, 2018 Author Share Posted May 15, 2018 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 .: if have error return 0 if nt have error return path+name folder, return 4 No Folders Found ; 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 return 4 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...
Earthshine Posted May 15, 2018 Share Posted May 15, 2018 You might want the mods to move this to snippets as suggested by a Moderator. My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
faustf Posted May 15, 2018 Author Share Posted May 15, 2018 what is snippets ? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 15, 2018 Moderators Share Posted May 15, 2018 It's fine to leave where it is. The implication for anything in Examples is use at your own risk "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