Jump to content
Sign in to follow this  

find next file based on date ?

Recommended Posts



i 've a request about file indexing.

Have a directory with > 35.000 files. Custom filename is spoken eg: #630YOC01

# = color flag

6 = width

30 = height

Y = type

OC01 = free user name/code

In these days receive a task from my boss. I must insert in a database, for each file, these info to allow statistics.

No big problem, find all mysql stuff on forum. But I want to know how list files in a directory starting from recent back to older.

I know that is indifferent for first insert in db, but later i need to build function that list/index only last files, or given date,

to keep update database day by day.

thank you for any info,


Share this post

Link to post
Share on other sites

You also can use _FileListToArray so i did several month ago:

#include <Array.au3>
#include <Date.au3>
#include <File.au3>

Global $sdateStart = "20121201", $sdateEnd
$sFolder = "D:\Programme\AutoIt3\MyProjects\YT-DL" ;without ending backslash
Global $a2D

$a2D = _FileListToArrayBetween2Days($sFolder, $sdateStart, $sdateEnd)

; Function Name:   _FileListToArrayBetweenDates($sFolder, $sdateStart, $sdateEnd)
; Description::    returns the files between $sdateStart and $sdateEnd (start and enddate are included)
; Parameter(s):    $sFolder = folder which is searched
;                 $sdateStart    = the oldest date of filemodification to be returned
;                 $sdateEnd     = the youngest date of filemodification to be returned
; Requirement(s):  AutoIt
; Return Value(s): 2D Array with filename(s) and modificationdate
; Author(s):       autoBert (www.autoit.de)
Func _FileListToArrayBetween2Days($sFolder, $sdateStart = "", $sdateEnd = "")
    If $sdateEnd = "" Then $sdateEnd = @YEAR & @MON & @MDAY
    $aRes = _FileListToArray($sFolder) ;All Files
    $j = 0 ;Counter for Resultarray

    Dim $aRes2D[$aRes[0] + 1][2]
    For $i = 1 To $aRes[0]
        $sFileDate = FileGetTime($sFolder & "\" & $aRes[$i], 0, 1)
        ConsoleWrite($aRes[$i] & @TAB & $sFileDate & @CRLF)
        If $sFileDate >= $sdateStart And $sFileDate <= $sdateEnd Then
            $j += 1
            $aRes2D[$j][0] = $aRes[$i]
            $aRes2D[$j][1] = $sFileDate
    $aRes2D[0][0] = $j
    ReDim $aRes2D[$j + 1][2]
    _ArraySort($aRes2D, 0, 1, 0, 1)
    Return $aRes2D
EndFunc   ;==>_FileListToArrayBetween2Days

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