FileIsInDirectory function
Checks whether the specified file name shares the path specified in Directory.
Declaration
function FileIsInDirectory(const Filename: string;
const Directory: string): BooleanArguments
Filename | The name of the file to be checked. |
Directory | The name of the directory compared to the file name. |
Function result
Returns True if the file and directory share the same paths.
Description
FileIsInDirectory is a Boolean function used to determine whether
the file in
FileName is located in
Directory.
FileIsInDirectory 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. FileIsInDirectory does not verify whether Directory 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 := FileIsInDirectory(sFile, sDir);
ShowMessage('File: ' + sFile + LineEnding +
'is in Directory: ' + sDir + '?' + LineEnding +
'FileIsInDirectory() result is: ' + bResult.ToString(TUseBoolStrs.True) + '.');See also
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
