Skip to content

FSearch

Search for file in search path.

Declaration

Source position: unix.pp line 154

  function FSearch(const path: RawByteString; dirlist: RawByteString; 
                  CurrentDirStrategy: TFSearchOption) : RawByteString;
  function FSearch(const path: RawByteString; dirlist: RawByteString)
                   : RawByteString;
  function FSearch(const path: UnicodeString; dirlist: UnicodeString; 
                  CurrentDirStrategy: TFSearchOption) : UnicodeString;
  function FSearch(const path: UnicodeString; dirlist: UnicodeString)
                   : UnicodeString;

Description

FSearch searches in DirList, a colon separated list of directories, for a file named Path. It then returns a path to the found file.

The CurrentDirStrategy determines how the current directory is treated when searching:

NoCurrentDirectory
Do not search the current directory unless it is specified in the search path.
CurrentDirectoryFirst
Search the current directory first, before all directories in the search path.
CurrentDirectoryLast
Search the current directory last, after all directories in the search path

It is mainly provided to mimic DOS search path behaviour. Default behaviour is to search the current directory first.

Errors

An empty string if no such file was found.

See also

Name Description
#rtl.unixutil.FNMatch Check whether filename matches wildcard specification

Example

Program Example46;
{ Program to demonstrate the FSearch function. }
Uses BaseUnix, Unix, Strings;
begin
  Writeln ('ls is in : ',FSearch ('ls',strpas(fpGetenv('PATH'))));
end.