- Offizieller Beitrag
Hi,
da recht häufig eine Dateiauflistung nach Datumskriterien weiterbearbeitet wird, halte ich es für sinnvoll, dass man doch die Listfunktion bereits dafür mit einer Option versieht. Wird diese Option nicht genutzt, führt dies auch zu keinerlei Verlangsamung der originalen Funktion, da der Timestamp erst im Anschluß des Standardablaufs ermittelt wird.
_FileListToArray
; #FUNCTION# ====================================================================================================================
; Name...........: _FileListToArray
; Description ...: Lists files and\or folders in a specified path (Similar to using Dir with the /B Switch)
; Syntax.........: _FileListToArray($sPath[, $sFilter = "*"[, $iFlag = 0]])
; Parameters ....: $sPath - Path to generate filelist for.
; $sFilter - Optional the filter to use, default is *. Search the Autoit3 helpfile for the word "WildCards" For details.
; $iFlag - Optional: specifies whether to return files folders or both
; |$iFlag= 0 (Default) Return both files and folders
; |$iFlag= 1 Return files only
; |$iFlag= 2 Return Folders only
; ******** $iDate - Optional: specifies to get additional time stamp ('YYYYMMDDHHMMSS')
; ******** |$iDate=-1 (Default) No time stamp
; ******** |$iDate= 0 Gets modification time stamp
; ******** |$iDate= 1 Gets creation time stamp
; ******** |$iDate= 2 Gets last access time stamp
; Return values .: @Error - 1 = Path not found or invalid
; |2 = Invalid $sFilter
; |3 = Invalid $iFlag
; |4 = No File(s) Found
; Author ........: SolidSnake <MetalGX91 at GMail dot com>
; Modified.......: BugFix (additional time stamp)
; Remarks .......: The array returned is one-dimensional and is made up as follows:
; $array[0] = Number of Files\Folders returned
; $array[1] = 1st File\Folder
; $array[2] = 2nd File\Folder
; $array[3] = 3rd File\Folder
; $array[n] = nth File\Folder
; ******** By using additional time stamp the array returned is two-dimensional:
; ******** $array[0][0] = Number of Files\Folders returned
; ******** $array[1][0] = 1st File\Folder, $array[1][1] = 1st time stamp
; ******** $array[2][0] = 2nd File\Folder, $array[2][1] = 2nd time stamp
; ******** $array[3][0] = 3rd File\Folder, $array[3][1] = 3rd time stamp
; ******** $array[n][0] = nth File\Folder, $array[n][1] = nth time stamp
; Related .......:
; Link ..........:
; Example .......: Yes
; Note ..........: Special Thanks to Helge and Layer for help with the $iFlag update speed optimization by code65536, pdaughe
; ===============================================================================================================================
Func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0, $iDate = -1)
Local $hSearch, $sFile, $sFileList, $sDelim = "|"
$sPath = StringRegExpReplace($sPath, "[\\/]+\z", "") & "" ; ensure single trailing backslash
If Not FileExists($sPath) Then Return SetError(1, 1, "")
If StringRegExp($sFilter, "[\\/:><\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
$hSearch = FileFindFirstFile($sPath & $sFilter)
If @error Then Return SetError(4, 4, "")
While 1
$sFile = FileFindNextFile($hSearch)
If @error Then ExitLoop
If ($iFlag + @extended = 2) Then ContinueLoop
$sFileList &= $sDelim & $sFile
WEnd
FileClose($hSearch)
If Not $sFileList Then Return SetError(4, 4, "")
If $iDate = -1 Then
Return StringSplit(StringTrimLeft($sFileList, 1), "|")
Else
Local $aContent = StringSplit(StringTrimLeft($sFileList, 1), "|")
Local $aOut[$aContent[0]+1][2] = [[$aContent[0]]]
For $i = 1 To $aContent[0]
$aOut[$i][0] = $aContent[$i]
$aOut[$i][1] = FileGetTime($sPath & $aContent[$i], $iDate, 1)
Next
Return $aOut
EndIf
EndFunc ;==>_FileListToArray