TFileSearcher.Search procedure
Searches for files or directories in the specified path(s) using the specified options.
Declaration
procedure Search(const ASearchPath: string;
const ASearchMask: string='';
ASearchSubDirs: Boolean=True;
CaseSensitive: Boolean=False)Arguments
ASearchPath | One or more paths used to search for files. |
ASearchMask | One or more masks used to determine file names that match in the search. |
ASearchSubDirs | Indicates if subdirectories are searched recursively. |
CaseSensitive | Indicates if file names are compared using case sensitivity. |
Description
Search is a method used to search for files or directories matching
the specified file masks found in the specified search paths.
ASearchPath contains one or more paths examined in the method, and
can contain multiple path names separated by the value in
PathSeparator. Each delimited path value in ASearchPath is resolved
by calling the
ResolveDots function, and processed in the method.
For example:
'c:\path\to\dir;c:\path\to\another\dir' '/home/user/path/to/dir;/home/user/path/to/another/dir'
Please note that leading or trailing white space in a search path is treated as part of the path specification. It is not trimmed, and will most likely prevent a match for the path value.
ASearchMask contains one or more file masks which determine the
matching files in the method. It may contain multiple file masks separated by
the value in the
MaskSeparator property. For example:
'*.pas;*.pp;*.lpr'
Please note that leading or trailing white space in a file mask is treated as part of the file specification. It is not trimmed, and will most likely prevent a match for the mask value.
ASearchSubDirs includes subdirectories found in ASearchPath in the
search process when set to
True. When set to
False only the
specified path(s) are searched and their subdirectories are ignored. The
default value is
True and includes subdirectories.
CaseSensitive determines whether file masks in ASearchMask are
handled in a case-sensitive manner. The default value is
False.
Use the FileAttribute property to control the file attributes needed
for any file that is considered a match in the search process. The default
value (faAnyFile) allows all files to be considered.
Use the DirectoryAttribute property to control the directory
attributes needed for any directory that is considered a match in the search
process. The default value (faDirectory) includes directories.
Use the FollowSymLink property to indicate whether symbolic links
in the file system are followed in the method. When enabled, a path or file
name that is a symbolic link is expanded (when accepted) to get the real path
on the local file system. By default, FollowSymLink is enabled in TFileSearcher.
Search processes each of the path values found in ASearchPath. FindFirstUTF8 is called to get file and directory attributes examined in the process. Values in FileAttribute and DirectoryAttribute are checked to determine which directories and files are available in the method. FollowSymLink determines whether an internal hash of visited directories is maintained in the method and used to resolve symbolic links.
The OnQueryFileFound and OnQueryDirectoryFound events handlers are signalled (when assigned) to allow the application to include or exclude each directory or file found in the process. Arguments passed to these handlers include the fully-qualified path or file name returned by ExpandFilenameUtf8.
When a matching file is found, the OnFileFound event is signalled. When a matching directory is found, the OnDirectoryFound event is signalled. When a new directory is processed in the method, the OnDirectoryEnter event is signalled.
Applications must assign a handler routine for these events to respond to the notifications. You can abort the search process by calling the Stop method in the handlers for these events.
Search is used in the implementation of routines like CopyFile, CopyDirTree, FindAllFiles, and FindAllDirectories.
Errors
An Exception is raised if Search is called while a previous call to the method is already running.
See also
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
