CODE
;===============================================================================
;
; Function Name: _FileGetTreeList
; Description: Returns a recursive list of directories
; Parameter(s): $Path = root path to begin the listing from
; $ProgressTitle = A title to put on a progress window. Empty String = no progress window
; Requirement(s): $Path is an existing directory
; Return Value(s): A 1-based array containing the full path of all found directories
; Note: Upon return, @Extended will contain a count of files (non-folders) found while searching for folders
; Author(s): Mike Ratzlaff <mike@ratzlaff.org>
; Revision: 20050622A
;
;===============================================================================
;
Func _FileGetTreeList($Path, $ProgressTitle = @ScriptName)
Dim $aDirList[100], $TotalFiles = 0
If $ProgressTitle <> '' Then ProgressOn($ProgressTitle, 'Scanning directories...', '', -1, -1, 16)
If _FileIsDir($Path) Then
$TotalFiles = __FileGetTreeList($aDirList, $Path, $ProgressTitle)
EndIf
If $ProgressTitle <> '' Then ProgressOff()
SetExtended($TotalFiles)
ReDim $aDirList[$aDirList[0]+1]
Return $aDirList
EndFunc
Func __FileGetTreeList(ByRef $aDirList, $Path, $ProgressTitle)
Dim $hndSearch_Dirs, $FileCount
If $ProgressTitle <> '' Then ProgressSet(random(99), $Path)
;Add the current directory on to the list
$aDirList[0] = $aDirList[0] + 1
If $aDirList[0] > UBound($aDirList) - 1 Then ReDim $aDirList[$aDirList[0] + 20]
$aDirList[$aDirList[0]] = $Path
;Scan for more directories
$hndSearch_Dirs = FileFindFirstFile($Path & '\*')
If $hndSearch_Dirs <> -1 Then
$sFileName = FileFindNextFile($hndSearch_Dirs)
While Not @error
If _FileIsDir($Path & '\' & $sFileName) Then
;Recurse into the directory, if it's not a special directory
If $sFileName <> '.' And $sFileName <> '..' Then
$FileCount = $FileCount + __FileGetTreeList($aDirList, $Path & '\' & $sFileName, $ProgressTitle)
EndIf
Else
;Add to the filecount
$FileCount = $FileCount + 1
EndIf
$sFileName = FileFindNextFile($hndSearch_Dirs)
WEnd
EndIf
FileClose($hndSearch_Dirs)
Return $FileCount
EndFunc
My _FileFindAllR function will return a list of files, found recursively, that match a given mask and attribute filter. This function also has an optional progress meter. The speed has been optimized by pre-fetching the directory structure and file count, so that these items don't have to be calculated dynamically.
CODE
;===============================================================================
;
; Function Name: _FileFindAllR
; Description: Returns a recursive list of files
; Parameter(s): $Path = root path to begin the listing from
; $Mask = file mask to match
; $AttribFilter = File Attributes to filter files through. See _FileFilterAttrib for details
; $ProgressTitle = A title to put on a progress window. Empty String = no progress window
; Requirement(s): $Path is an existing directory
; Return Value(s): A 1-based array containing the full path of all found files
; Author(s): Mike Ratzlaff <mike@ratzlaff.org>
; Revision: 20050622A
;
;===============================================================================
;
;Returns a recursive list of files under $Path, matching $Mask, and filtered through $AttribFilter
Func _FileFindAllR($Path, $Mask='*', $AttribFilter='dhs', $ProgressTitle = @ScriptName)
Dim $i, $aDirList = _FileGetTreeList($Path, $ProgressTitle), $FileList[@extended + 1]
If $ProgressTitle <> '' Then ProgressOn($ProgressTitle, 'Scanning files...', '', -1, -1, 16)
For $i = 1 to $aDirList[0]
If $ProgressTitle <> '' Then ProgressSet($i * 100 / $aDirList[0], $aDirList[$i])
__FileFindAllR($FileList, $aDirList[$i], $Mask, $AttribFilter)
Next
If $ProgressTitle <> '' Then ProgressOff()
ReDim $FileList[$FileList[0]+1]
Return $FileList
EndFunc
Func __FileFindAllR(ByRef $aFileList, $Path, $Mask, $AttribFilter)
Dim $hndSearch_Files
$hndSearch_Files = FileFindFirstFile($Path & '\' & $Mask)
If $hndSearch_Files <> -1 Then
$sFileName = FileFindNextFile($hndSearch_Files)
While Not @error
If _FileFilterAttrib($Path & '\' & $sFileName, $AttribFilter) And $sFileName <> '.' And $sFileName <> '..' Then
$aFileList[0] = $aFileList[0] + 1
$aFileList[$aFileList[0]] = $Path & '\' & $sFileName
EndIf
$sFileName = FileFindNextFile($hndSearch_Files)
WEnd
FileClose($hndSearch_Files)
EndIf
EndFunc
These functions require my _FileFilterAttrib function, and also my _FileIsDir function:
CODE
;===============================================================================
;
; Function Name: _FileIsDir
; Description: Returns true or false weather given file is a directory or not
; Parameter(s): $Path
; Requirement(s):
; Return Value(s): 0 = not a directory or does not exist, 1 = file exists and is a directory
; Author(s): Mike Ratzlaff <mike@ratzlaff.org>
; Revision: 20050623A
;
;===============================================================================
;
Func _FileIsDir($Path)
;This function checkes to see if $FileName exists and if it is a Directory
If StringInStr(FileGetAttrib($Path),'D') Then Return 1
Return 0
EndFunc




