Jump to content
Sign in to follow this  

Process All Files in Folder by date as opposed to name

Recommended Posts

I have a folder where there are several files I need to process. Files get added on a continuous basis. I have been using FileFindFirstFile and FileFindNextFile successfully for a while now but ran into a situation where It would be much better to process the files oldest first. Is there a way to control FileFindNextFile so that it returns the oldest file instead of the first file alphebetically?

Any thoughts on a different approach get process the files oldest first?

Share this post

Link to post
Share on other sites

Store them in an array and the FileGetTime attribute. Once you store them in an array you reference it via the array number +1 or -1 instead of the FileFindNextFile. You will also have to use the _ArraySort UDF given in the help file.

Share this post

Link to post
Share on other sites

Thanks for the tips.

Here is the solution I came up with.

$FileList=_FileListToArray($Folder, "*." & $extension)
    $err = @error
    If (@Error=4) Then
        $filename = ""
        $UBound = UBound($Filelist)-1

        Dim $CombinedArray[$UBound][2]
        for $i=1 to $Ubound
            $datetime = FileGetTime($folder & "\" & $FileList[$i], 0, 1)
            $CombinedArray[$i-1][0] = $FileList[$i]
            $CombinedArray[$i-1][1] = $datetime
        _ArraySort($CombinedArray, 0, 0, 0, 1)  
        $filename = $CombinedArray[0][0]

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...