Skip to content

FileSearch

Search for a file in a path.

Declaration

Source position: filutilh.inc line 192

  function FileSearch(const Name: UnicodeString; 
                     const DirList: UnicodeString; 
                     Options: TFileSearchOptions) : UnicodeString;
  function FileSearch(const Name: UnicodeString; 
                     const DirList: UnicodeString; 
                     ImplicitCurrentDir: Boolean) : UnicodeString;
  function FileSearch(const Name: RawByteString; 
                     const DirList: RawByteString; 
                     Options: TFileSearchOptions) : RawByteString;
  function FileSearch(const Name: RawByteString; 
                     const DirList: RawByteString; 
                     ImplicitCurrentDir: Boolean) : RawByteString;

Description

FileSearch looks for the file Name in DirList, where dirlist is a list of directories, separated by semicolons or colons. It returns the full filename of the first match found. The optional Options parameter may be specified to influence the behaviour of the search algorithm. It is a set of the following options:

sfoImplicitCurrentDir
Always search the current directory first, even if it is not specified.
sfoStripQuotes
Strip quotes from the components in the search path.

A deprecated form of the function allowed to specify using the boolean ImplicitCurrentDir parameter whether the current directory was searched implicitly or not. By default, the current directory is searched.

Errors

On error, an empty string is returned.

See also

Name Description
ExpandFileName Expand a relative filename to an absolute filename.
FindFirst Start a file search and return a findhandle

Example

Program Example41;
{ Program to demonstrate the FileSearch function. }
Uses Sysutils;
Const
{$ifdef unix}
  FN = 'find';
  P = '.:/bin:/usr/bin';
{$else}
  FN = 'find.exe';
  P = 'c:\dos;c:\windows;c:\windows\system;c:\windows\system32';
{$endif}
begin
  Writeln ('find is in : ',FileSearch (FN,P));
end.