[Overview][Constants][Types][Classes][Procedures and functions][Index] Reference for unit 'FileUtil' (#lazutils)

TFileSearcher.Search

Searches for files or directories in the specified path(s) using the specified options.

Declaration

Source position: fileutil.pas line 144

public procedure TFileSearcher.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.

The value in the CaseSensitive argument is used to add or remove mask options for the search mask in ASearchMask. Set CaseSensitive to True before calling Search to perform file name comparisons with case sensitivity.

ASearchSubDirs includes subdirectories found in ASearchPath in the search process when set to True. When set to False only the specified paths are searched and their subdirectories are ignored.

Set the value in FileAttribute to control the file attributes included in the search process. The default value (faAnyFile) allows all files to be considered.

Set the value in DirectoryAttribute to control whether directory names are included in the search process. The default value (faDirectory) includes directory names.

Set the value in FollowSymLink to indicate whether symbolic links in the file system are followed in the method.

When a matching file is found, the OnFileFound event is signalled. For directories, the OnDirectoryFound event is signalled. When a new directory is processed in the method, the OnDirectoryEnter events is signalled. Applications must assign a handler for the events to respond to the notifications. You can abort the search process by calling the Stop method in the handlers for these events.

Errors

Calls RaiseSearchingError to raise an exception if the Search method has already been called and has not completed.

See also

TFileSearcher.OnFileFound

  

Event handler signalled when a file matching the file mask is found in the Search method.

TFileSearcher.OnDirectoryFound

  

Event handler signalled when a new directory is found in the Search method.

TFileSearcher.OnDirectoryEnter

  

Event handler signalled when a new directory is processed in the Search method.

TFileSearcher.FileAttribute

  

File attribute needed for any file considered a match in the Search method.

TFileSearcher.DirectoryAttribute

  

File attribute needed for directories considered a match in the Search method.

TFileSearcher.FollowSymLink

  

Indicates if a search process directory paths that are symbolic links.

TFileSearcher.PathSeparator

  

Character used as a delimiter between directory paths.

TFileSearcher.MaskSeparator

  

Character used as a delimiter between file masks.

TFileIterator.Stop

  

Stops the search process.


Version 3.2 Generated 2024-02-25 Home