Sign in Join
FPDoc Onlineexperiment

FileIsInPath function

In unit FileUtil

Checks whether the specified file name shares the path specified in Path.

Declaration

pascal
function FileIsInPath(const Filename: string; const Path: string)
: Boolean

Description

FileIsInPath is a Boolean function used to determine whether the file in FileName is located in the specified Path. FileIsInPath calls the CleanAndExpandFilename and CleanAndExpandDirectory routines to resolve drive letters or relative path information included in the arguments.

The return value is True when the resolved paths for the arguments contain the same values. FileIsInPath does not verify whether Path or FileName actually exist on the local file system. It compares the specified string values only.

Use DirectoryExists or DirectoryExistsUTF8 to determine whether a path exists on the local file system.

Use FileExists or FileExistsUTF8 to determine whether a file exists on the local file system.

Example:

// uses FileUtil;
// ...
// var
//   sDir, sFile: String;
//   bResult: Boolean;
// ...
// neither the file nor the directory exist on the file system
sDir := 'q:\bogus\path\';
sFile := 'q:\bogus\path\..\path\filename.ext';
bResult := FileIsInPath(sFile, sDir);

ShowMessage('File: ' + sFile + LineEnding +
  'is in Path: ' + sDir + '?' + LineEnding +
  'FileIsInPath() result is: ' + bResult.ToString(TUseBoolStrs.True) + '.');

See also

An experiment, built from Lazarus main 2dfa93c66e of 10-22-2026. Not the official Lazarus documentation.