FindDiskFilename function
Finds the file name that most closely matches the specified file name.
Declaration
function FindDiskFilename(const Filename: string): stringDescription
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.
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
- ResolveDots
- CompareFilenamesIgnoreCase
An experiment, built from Lazarus main 2dfa93c66e of 10-22-2026. Not the official Lazarus documentation.
