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

CreateAbsolutePath

Returns an absolute path relative to the specified base directory (when needed).

Declaration

Source position: lazfileutils.pas line 66

function CreateAbsolutePath(

  const Filename: string;

  const BaseDirectory: string

):string;

Arguments

Filename

  

File name with relative path references resolved in the routine.

BaseDirectory

  

Base directory used to resolve a relative path reference in the file name.

Function result

Fully-qualified absolute path to the specified file relative to a given base directory.

Description

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.

Remark: CreateAbsolutePath does not validate path or file name information; the file or directory does not have to exist on the local file system.

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

FilenameIsAbsolute

  

Determines if the specified value is an absolute file path (not a relative one).

TrimFileName

  

Removes leading and trailing spaces, and resolves special characters.

AppendPathDelim

  

Adds a trailing path delimiter when needed.

ExtractFileDrive


Version 3.2 Generated 2024-02-25 Home