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

FindDiskFilename

Finds the file name that most closely matches the specified file name.

Declaration

Source position: fileutil.pas line 95

function FindDiskFilename(

  const Filename: string

):string;

Arguments

Filename

  

The qualified path (optional) and file name to locate in the routine.

Function result

Resolved path and file name which is the case-insensitive match for the specified value.

Description

FindDiskFilename is a String function used to get the file name which most closely matches the value in the FileName argument. It does not use case-sensitivity when comparing file names - regardless of the platform. In addition, the file must exist on the local file system.

FileName can include a fully-qualified path including a drive letter on Windows platforms. A drive letter in the value is always converted to uppercase. The path to the file is extracted and sanitized to resolve relative path references.

The file path is used to locate and compare all files in the directory by calling FindFirstUTF8 and FindNextUTF8. Each file entry is examined using CompareFilenamesIgnoreCase for a case-insensitive match for the specified file name. When a single match is found, its fully qualified path and file name are assigned as the return value. If more than one file is a match, the result is ambiguous and the resolved value for the original FileName argument is returned.

Remark: The "All Files" mask for the platform is used to find the files in the path. This can be time consuming when a folder has a large number of files.

Example:

// uses FileUtil;
// var AFileName, AResult: String;
// ...

// Windows
AFileName := 'c:\WINDOWS\WIN.INI';
AResult := FindDiskFileName(AFileName);
// AResult contains: 'C:\Windows\win.ini';

// UNIX-like platforms
AFileName := '/ETC/FONTS/FONTS.CONF';
AResult := FindDiskFileName(AFileName);
// AResult contains: '/etc/fonts/fonts.conf';

See also

FindFirstUTF8

FindNextUTF8

GetAllFilesMask

  

Gets the file mask representing all files in a file filter.

ResolveDots

  

Resolves relative path references and removes duplicate path delimiters.

CompareFilenamesIgnoreCase

  

Gets the relative sort order for case-insensitive file names.


Version 3.2 Generated 2024-02-25 Home