Jump to content

_FileListToArrayEx (list directory, subdirectory, and files)


OnePiece

Recommended Posts

Ragazzi niente di che solo cosi per hoby diciamo ecco mi sono messo aggiornare un del function del autoit il _FileListToArray, per farlo supportare la ricerca anche in subdirectory, dire il vero ci o messo quasi 4 giorni era come un indovinello ma in fine ecco e in fine contenti, e uscito un codice davvero pulito con solo 22 line aggiunte a quello originale

Il _FileListToArrayEx lavora quasi 20% piu veloce del (cmd.exe Dir)

#include <Constants.au3>

$foo = Run(@ComSpec & " /c " & "DIR " & '"' & @windowsdir & '"' & " /A /b /s /ong", "", @SW_HIDE, $STDOUT_CHILD)

While 1

$line &= StdoutRead($foo)

If @error Then ExitLoop

Wend

http://www.autoitscr...ListToArray.htm

$iFlag = 4 Cercare anche in sotto direttori

$iFlag = 8 Return Full Path


#include <Array.au3>

Global $a1, $b1
$a1 = TimerInit()
$b1 = _FileListToArrayEx(@WindowsDir, "*", 12)
;$b1 = _FileListToArrayEx(@UserProfileDir & "\Pictures", "*.png|*.jpg|*.bmp")
$a1 = TimerDiff($a1)
_ArrayDisplay($b1, $a1)

; #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 *. (Multiple filter groups such as "All "*.png|*.jpg|*.bmp") Search the Autoit3 helpfile for the word "WildCards" For details.
; $iFlag - Optional: specifies whether to return files folders or both Or Full Path (add the flags together for multiple operations):
; |$iFlag = 0 (Default) Return both files and folders
; |$iFlag = 1 Return files only
; |$iFlag = 2 Return Folders only
; |$iFlag = 4 Search subdirectory
; |$iFlag = 8 Return Full Path
; 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.......:
; 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
; Related .......:
; Link ..........:
; Example .......: Yes
; Note ..........: Special Thanks to Helge and Layer for help with the $iFlag update speed optimization by code65536, pdaughe
; Update By DXRW4E
; ===================================================================================================================================
Func _FileListToArrayEx($sPath, $sFilter = "*", $iFlag = 0)
Local $hSearch, $sFile, $sFileList, $iFlags = StringReplace(BitAND($iFlag, 1) + BitAND($iFlag, 2), "3", "0"), $sSDir = BitAND($iFlag, 4), $FPath = "", $sDelim = "|", $sSDirFTMP = $sFilter
$sPath = StringRegExpReplace($sPath, "[\\/]+\z", "") & "\" ; ensure single trailing backslash
If Not FileExists($sPath) Then Return SetError(1, 1, "")
If BitAND($iFlag, 8) Then $FPath = $sPath
If StringRegExp($sFilter, "[\\/:><]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
If Not ($iFlags = 0 Or $iFlags = 1 Or $iFlags = 2 Or $sSDir = 4 Or $FPath <> "") Then Return SetError(3, 3, "")
$hSearch = FileFindFirstFile($sPath & "*")
If @error Then Return SetError(4, 4, "")
Local $hWSearch = $hSearch, $hWSTMP = $hSearch, $SearchWD, $sSDirF[3] = [0, StringReplace($sSDirFTMP, "*", ""), "(?i)(" & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace("|" & $sSDirFTMP & "|", '\|\h*\|[\|\h]*', "\|"), '[\^\$\(\)\+\[\]\{\}\,\.\=]', "\\$0"), "\|([^\*])", "\|^$1"), "([^\*])\|", "$1\$\|"), '\*', ".*"), '^\||\|$', "") & ")"]
While 1
$sFile = FileFindNextFile($hWSearch)
If @error Then
If $hWSearch = $hSearch Then ExitLoop
FileClose($hWSearch)
$hWSearch -= 1
$SearchWD = StringLeft($SearchWD, StringInStr(StringTrimRight($SearchWD, 1), "\", 1, -1))
ElseIf $sSDir Then
$sSDirF[0] = @extended
If ($iFlags + $sSDirF[0] <> 2) Then
If $sSDirF[1] Then
If StringRegExp($sFile, $sSDirF[2]) Then $sFileList &= $sDelim & $FPath & $SearchWD & $sFile
Else
$sFileList &= $sDelim & $FPath & $SearchWD & $sFile
EndIf
EndIf
If Not $sSDirF[0] Then ContinueLoop
$hWSTMP = FileFindFirstFile($sPath & $SearchWD & $sFile & "\*")
If $hWSTMP = -1 Then ContinueLoop
$hWSearch = $hWSTMP
$SearchWD &= $sFile & "\"
Else
If ($iFlags + @extended = 2) Or StringRegExp($sFile, $sSDirF[2]) = 0 Then ContinueLoop
$sFileList &= $sDelim & $FPath & $sFile
EndIf
WEnd
FileClose($hSearch)
If Not $sFileList Then Return SetError(4, 4, "")
Return StringSplit(StringTrimLeft($sFileList, 1), "|")
EndFunc

Ciao a tutti.

Edited by OnePiece
Link to comment
Share on other sites

  • 8 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...