CreateAbsolutePath function
Returns an absolute path relative to the specified base directory (when needed).
Declaration
function CreateAbsolutePath(const Filename: string;
const BaseDirectory: string): stringDescription
CreateAbsolutePath is a
String function used to get the
absolute path to the file specified in the
Filename argument. A
relative path reference in Filename is resolved to the path in the
BaseDir argument. The return value contains the fully-qualified
absolute path to the specified file name.
When Filename is an empty string ('') or already uses an absolute path reference, the value in Filename is used as the return value.
For the Windows platform, a file name which starts with '\' (root directory on the current drive) is resolved to the drive letter and root directory in BaseDIr. For all other platforms, the values in BaseDir and PathDelim are prepended to the relative path information in FileName.
CreateAbsolutePath calls TrimFileName to remove leading or trailing whitespace or duplicate path delimiters in the return value.
Example:
// uses LazFileUtils;
// var vFile, vBaseDir: String;
vFile := '.\foo\bar\baz.txt';
vBaseDir := 'c:\temp';
ShowMessage('File: ' + vFile + LineEnding +
'Base Directory: ' + vBaseDir + LineEnding +
'Absolute Path: ' + CreateAbsolutePath(vFile, vBaseDir));
vFile := '\foo\\bar\\baz.txt';
vBaseDir := 'c:\temp';
ShowMessage('File: ' + vFile + LineEnding +
'Base Directory: ' + vBaseDir + LineEnding +
'Absolute Path: ' + CreateAbsolutePath(vFile, vBaseDir));See also
An experiment, built from Lazarus main 2dfa93c66e of 10-22-2026. Not the official Lazarus documentation.
