So, first I started by writing a file-filter routine, that takes a file and a filter string and returns true or false based on weather the file matches the filter:
Func _FileFilterAttrib($FileName, $Attrib) Dim $Return=0, $FileAttrib, $i, $ch If FileExists($FileName) Then $Return=-1 $FileAttrib = FileGetAttrib($FileName) For $i = 1 to StringLen($Attrib) $ch = StringMid($Attrib,$i,1) If StringIsUpper($ch) Then ;This attribute must be on the list If not StringInStr($FileAttrib, $ch) then $Return = 0 Else ;This attribute must not be on the list If StringInStr($FileAttrib, StringUpper($ch)) then $Return = 0 EndIf Next EndIf Return $Return EndFunc
The way the filter works is this:
It is a string of characters, the same of which are returned by the function FileGetAttribute
If a character is uppercase, then the file MUST hast this attribute to pass the filter, and if the character is lower-case then the file must NOT have this attribute to pass the filter.
For example, the default filter 'dhs' will only return true on files that are not directory, hidden, or system flagged. The filter 'D' would only return directories, and the filter 'Dh' would return directories that are not hidden.
The next step is to wrap this in a file searching routine, that would search an entire folder, first matching based on a filename mask, then filter by attributes:
Func _FileFindAll($Path, $Mask="*", $AttribFilter='dhs') Dim $FileList, $FileListSize = 0, $hndFile_Search, $CurFile If FileIsDir($Path) Then;Path exists and is a directory $hndFile_Search = FileFindFirstFile($Path & '\' & $Mask) If $hndFile_Search<>-1 Then; at least 1 file/directory exists $CurFile = FileFindNextFile($hndFile_Search) While not @error;loop through found files If FileFilterAttrib($Path & '\' & $CurFile, $AttribFilter) Then;file passes attribute filter $FileListSize = $FileListSize + 1 If $FileListSize > UBound($FileList) Then ReDim $FileList[$FileListSize+20];increase list size $FileList[$FileListSize - 1] = $CurFile EndIf $CurFile = FileFindNextFile($hndFile_Search) WEnd FileClose($hndFile_Search) ReDim $FileList[$FileListSize] Return $FileList EndIf EndIf Return 0 EndFunc
Calling it is pretty self-explanitory, I think:
returns an array where =number of results, and ...[x] are the file names.