Jump to content
Sign in to follow this  
faustf

udf Find Oldest and newest Folder

Recommended Posts

faustf

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

 

  • Like 1

Share this post


Link to post
Share on other sites
JLogan3o13

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:


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
faustf

yea is not perfect  udf  bu is perfectible , thankz  fo sudgest :D

 

Share this post


Link to post
Share on other sites
faustf
; #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

 

Share this post


Link to post
Share on other sites
Earthshine

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

 

Share this post


Link to post
Share on other sites
faustf

what is snippets ?

 

Share this post


Link to post
Share on other sites
JLogan3o13

It's fine to leave where it is. The implication for anything in Examples is use at your own risk


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
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
Sign in to follow this  

×