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

# CreateRelativePath

CreateRelativePath - given an absolute file path and aBaseDirectory, create a file path relative to the given base directory

## Declaration

Source position: fileutil.pas line 92

`function CreateRelativePath(`
`const Filename: String;`
`const BaseDirectory: String;`
`UsePointDirectory: Boolean = false`
`):String;`

## Arguments

`Filename` |  | The absolute FileName for which a relative path is to be created
`BaseDirectory` |  | BaseDirectory of the absolute search path

## Function result

The file name expressed as path relative to the current directory

## Description

CreateRelativePath - given an absolute path and a BaseDirectory, create a file path relative to the given base directory

The returned string includes the correct number of dots and double dots to signify relativity to the current directory (eg ../../or ..\..\ etc). The inverse operation is to create an absolute file path:

    RelPath:=CreateRelativePath(AbsPath,BaseDir);
    if FilenameIsAbsolute(RelPath) then
      NewAbsPath:=RelPath
    else
      NewAbsPath:=AppendPathDelim(BaseDir)+RelPath;

## Errors

If BaseDirectory is empty, functions exits and returns with Result equal to Filename; if Filename is empty, function exits with empty Result

The latest version of this document can be found at lazarus-ccr.sourceforge.net .