[Overview][Constants][Types][Classes][Procedures and functions][Index] |
Searches for files or directories in the specified path(s) using the specified options.
Source position: fileutil.pas line 153
public procedure TFileSearcher.Search( |
const ASearchPath: string; |
const ASearchMask: string = ''; |
ASearchSubDirs: Boolean = True; |
CaseSensitive: Boolean = False |
); |
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. |
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.
An Exception is raised if Search is called while a previous call to the method is already running.
|
Event handler signalled when a file matching the file mask is found in the Search method. |
|
|
Event handler signalled when a new directory is found in the Search method. |
|
|
Event handler signalled to accept or reject a subdirectory in the Search method. |
|
|
Event handler signalled to accept or reject a file name found using the class. |
|
|
Performs actions needed to accept or reject a directory name processed in the Search method. |
|
|
Performs actions needed to accept or reject a file name processed in the Search method. |
|
|
File attribute needed for any file considered a match in the Search method. |
|
|
File attribute needed for directories considered a match in the Search method. |
|
|
Indicates if a search process directory paths that are symbolic links. |
|
|
Character used as a delimiter between directory paths. |
|
|
Character used as a delimiter between file masks. |
|
|
Stops the search process. |
|
|
Copies all file system entries in a source directory to the destination directory using the specified options. |
|
|
Copies the source file to the destination file using the specified options. |
|
|
Returns the list of files in the specified path matching the search criteria. |
|
|
Stores directory names matching the search criteria in a TStringList class instance. |
|
|
Expands the values in FileName and BaseDir to an absolute file name. |
|
|
Implements a list for mask class instances. |
Version 4.0 | Generated 2025-05-03 | Home |