Function Reference


_FO_FileSearch

Returns a list of files in the specified directory.

#Include <FileOperations.au3>
_FO_FileSearch ( $sPath [, $sMask = '*' [, $fInclude=True [, $iDepth=125 [, $iFull=1 [, $iArray=1 [, $iTypeMask=1 [, $sLocale=0[, $vExcludeFolders = ''[, $iExcludeDepth = -1]]]]]]]]] )

Parameters

$sPath Search path
$sMask [optional] The mask depends on the parameter $TypeMask and can either be complete using the characters "*" and "?" (the default), or using only the file extensions. The character "|" is used as a delimiter. The default is '*', which means the search all files.
$fInclude [optional] Include or exclude the specified in a mask
    True - Find in accordance with mask (default)
    False - Find all except specified in a mask
$iDepth [optional] The depth of nesting of directories (0 - root directory; the default 125)
$iFull [optional] Paths in returned data
    0 - relative
    1 - Full path (by default)
    2 - File names with extension
    3 - File names without extension
$iArray [optional] Specifies the output: array or list
    0 - Delimited list @CRLF
    1 - Array, where $iArray[0]=number of files (by default)
    2 - Array, where $iArray[0] contains the first file
$iTypeMask [optional] Mask type
    0 - Auto detection (1 or 2)
    1 - Force the use of mask type: *.is?|s*.cp*. You can also specify a file name without wildcard characters "*" or "?" and without the extension and will be found (by default).
    2 - Force the use of mask type: tmp|bak|gid. Used only by file extension. The parameter $sLocale is ignored in this case.
$sLocale [optional] Case sensitivity.
    -1 - Not case sensitive (only for 'A-z').
    0 - Not case sensitive, by default. (for any characters)
    1 - Case sensitive (for any characters)
    <> - not case sensitive, specified range of characters from local languages. For example '-'. 'A-z' is not required, they are enabled by default.
$vExcludeFolders [optional] Excludes folders from search. List the folder names via the "|", for example, "Name1|Name2|Name3|".
$iExcludeDepth [optional] Nesting level for the parameter $vExcludeFolders. -1 by default, which means disabled.

Return Value

Success:Returns a list of files.
Failure:Returns an empty string and sets @error:
@error:1 - Invalid path
2 - Invalid mask
3 - Not found

Remarks

Be sure to check the @error, because in the absence of found files, you cannot use an array. This results in an error that cannot be found in the test.

Use _FO_CorrectMask, to correct the errors that can be tolerated by the user when creating a mask.
You cannot use both types of masks together. If auto detection is turned on ($iTypeMask=0) then if at least one of these three characters "*.?" uses the $iTypeMask=1, otherwise $iTypeMask=2.
In the GUI as a separator in the mask, you can use a different character, such as ";" or "," especially when using $iTypeMask=2, but in the function parameter to replace it with a "|". You can use the Opt("GUIDataSeparatorChar", Chr(1)), to set a separator for a Combo in the GUI.
Cannot create the directory depth of more than 125. To handle the long path prepend the path \\?\, for example "\\?\D:MyFolder"

Related

_FO_CorrectMask, _FO_FolderSearch

Example

; AZJIO
; http://www.autoitscript.com/forum/topic/133224-filesearch-foldersearch/
#include <Array.au3> ; for _ArrayDisplay
#include <FileOperations.au3>

; Files
;=======================================
$timer = TimerInit()
$FileList = _FO_FileSearch(@WindowsDir)
$timer = Round(TimerDiff($timer) / 1000, 2) & ' sec'
_ArrayDisplay($FileList, $timer & ' - All Files')
;=======================================
$timer = TimerInit()
$FileList = _FO_FileSearch(@WindowsDir, 'exe|dll', True, 0, 1, 0, 0)
$timer = Round(TimerDiff($timer) / 1000, 2) & ' sec'
MsgBox(0, $timer & ' - exe;dll', $FileList)
;=======================================
$timer = TimerInit()
$FileList = _FO_FileSearch(@WindowsDir, 'exe|dll', False, 0, 0, 0, 0)
$timer = Round(TimerDiff($timer) / 1000, 2) & ' sec'
MsgBox(0, $timer & ' - excluding exe|dll, relative', $FileList)
;=======================================
$timer = TimerInit()
$FileList = _FO_FileSearch(@WindowsDir, 'exe|dll', False, 0, 3, 0, 0)
$timer = Round(TimerDiff($timer) / 1000, 2) & ' sec'
MsgBox(0, $timer & ' - excluding exe|dll, file name without extension', $FileList)
;=======================================
$timer = TimerInit()
$FileList = _FO_FileSearch(@WindowsDir, 'tmp|bak|gid', True, 125, 0, 2)
$timer = Round(TimerDiff($timer) / 1000, 2) & ' sec'
_ArrayDisplay($FileList, $timer & ' - tmp|bak|gid, relative, array')
;=======================================
$timer = TimerInit()
$FileList = _FO_FileSearch(@WindowsDir, 'tmp|bak|gid', True, 125, 2)
$timer = Round(TimerDiff($timer) / 1000, 2) & ' sec'
_ArrayDisplay($FileList, $timer & ' - tmp|bak|gid, file name with extension')
;=======================================
; Invalid character in path
$FileList = _FO_FileSearch('C:\WIN>DOWS', '*')
If @error Then
    MsgBox(0, 'Error', '@error: ' & @error)
    ; Exit
EndIf
;=======================================
$timer = TimerInit()
$FileList = _FO_FileSearch(@WindowsDir, '*.is?|s*.cp*')
$timer = Round(TimerDiff($timer) / 1000, 2) & ' sec'
_ArrayDisplay($FileList, $timer & ' - *.is?|s*.cp*')
;=======================================
$timer = TimerInit()
$FileList = _FO_FileSearch(@WindowsDir, 'shell*.*|config.*')
$timer = Round(TimerDiff($timer) / 1000, 2) & ' sec'
_ArrayDisplay($FileList, $timer & ' - shell*.*|config.*')
;=======================================
; The use of a regular expression
$timer = TimerInit()
$FileList = _FO_FileSearch(@WindowsDir, '*', True, 125, 1, 0)
$FileList = StringRegExp($FileList, '(?mi)^(.*\.(?:exe|dll))(?:\r|\z)', 3)
$timer = Round(TimerDiff($timer) / 1000, 2) & ' sec'
_ArrayDisplay($FileList, UBound($FileList) & ' - ' & $timer & ' - RegExp')
;=======================================

; Folders and files
;=======================================
$List = _FO_FolderSearch(@WindowsDir & '\Web', '*', True, 0, 0, 0) & @CRLF & _FO_FileSearch(@WindowsDir & '\Web', '*', True, 0, 0, 0)
MsgBox(0, 'folders and files', $List)
;=======================================