Jump to content

udf Find Oldest and newest Folder


faustf
 Share

Recommended Posts

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 

; #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

 

Link to comment
Share on other sites

  • Moderators

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? :doh:

"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

; #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

  • Moderators

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...