Jump to content



Recommended Posts

I was just looking at the _FileListToArray() function in the file.au3 library. It's author SolidSnake notes in the comments that it is just like "DIR /B". But what if you don't want "DIR /B"? What if you want all the details?

Here is a new function:

Func _FileListToArray2($s_Path=@MyDocumentsDir, $s_Mask='*')
    $h_Search = FileFindFirstFile($s_Path & '\' & $s_Mask)
    $s_FileName = FileFindNextFile($h_Search)
    If Not @error Then
        Dim $a_File[100][10]
        While Not @error
            $s_FullName = $s_Path & '\' & $s_FileName
            $a_File[0][0] += 1
            If $a_File[0][0] >= UBound($a_File) Then
                ReDim $aFile[$a_File[0][0] * 2][10]
            $i_ExtMarker = StringInStr($s_FileName,'.',0,-1)
            If $i_ExtMarker Then
                $a_File[$a_File[0][0]][0] = StringLeft($s_FileName, $i_ExtMarker - 1)
                $a_File[$a_File[0][0]][1] = StringMid($s_FileName, $i_ExtMarker + 1)
                $a_File[$a_File[0][0]][0] = $s_FileName
                $a_File[$a_File[0][0]][1] = ''
            $a_File[$a_File[0][0]][2] = FileGetLongName($s_FullName)
            $a_File[$a_File[0][0]][3] = FileGetAttrib($s_FullName)
            $a_File[$a_File[0][0]][4] = FileGetSize($s_FullName)
            $a_File[$a_File[0][0]][5] = FileGetTime($s_FullName,0,1)
            $a_File[$a_File[0][0]][6] = FileGetTime($s_FullName,1,1)
            $a_File[$a_File[0][0]][7] = FileGetTime($s_FullName,2,1)
            $a_File[$a_File[0][0]][8] = FileGetVersion($s_FullName)
            $a_File[$a_File[0][0]][9] = FileGetShortName($s_FullName)
            $s_FileName = FileFindNextFile($h_Search)
        ReDim $a_File[$a_File[0][0] + 1][10]
        Return $a_File
        Return ''

Which returns a 1-based 2-dimensioned array that looks like this:

[0][0] = array size

[x][0] = file name (w/o extension)

[x][1] = file extension (w/o '.')

[x][2] = long file name w/ full path

[x][3] = file attributes

[x][4] = file size

[x][5] = file modification time

[x][6] = file creation time

[x][7] = file access time

[x][8] = file version code

[x][9] = short file name w/ full short path

So to get a list of files and sort them by their modification date:

$a_FileList = _FileListToArray2();default folder is My Documents
_ArraySort($a_FileList, 1, 1, $a_FileList[0][0], 10, 5); sort decending by modification date
_ArrayBox($a_FileList);display 2-d array

And _ArrayBox() is function I wrote to help display large 2-d arrays.

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

  • Recently Browsing   0 members

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