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

TryCreateRelativePath

Attempts to create a path in Dest relative to the path in Source.

Declaration

Source position: lazfileutils.pas line 67

function TryCreateRelativePath(

  const Dest: string;

  const Source: string;

  UsePointDirectory: Boolean;

  AlwaysRequireSharedBaseFolder: Boolean;

  out RelPath: string

):Boolean;

Arguments

Dest

  

Path to the destination directory (relative or absolute).

Source

  

Path to the source directory (relative or absolute).

UsePointDirectory

  

True if RelPath is set to '.' when an empty relative path ('') is derived from Source to Dest.

AlwaysRequireSharedBaseFolder

  

False requires use of absolute paths in both Source and Dest.

RelPath

  

Returns the relative path from Source to Dest derived in the routine.

Function result

Returns True if the path from Source to Dest is a relative path that can be derived using the arguments to the routine.

Description

Returns True if it is possible to create a relative path from Source to Dest. The function must be thread safe, so no expansion of filenames is done since this is not thread-safe (at least on Windows platform).

Remark: TryCreateRelativePath does not physically create any folders need for the derived relative path to Dest.

Examples:

- Dest = /foo/bar Source = /foo Result = True RelPath = bar
- Dest = /foo///bar Source = /foo// Result = True RelPath = bar
- Dest = /foo Source = /foo/bar Result = True RelPath = ../
- Dest = /foo/bar Source = /bar Result = True RelPath = ../foo/bar
- Dest = foo/bar Source = foo/foo Result = True RelPath = ../bar
- Dest = foo/bar Source = bar/foo Result = False (no shared base directory)
- Dest = /foo Source = bar Result = False (mixed absolute and relative)
- Dest = c:foo Source = c:bar Result = False (no expanding)
- Dest = c:\foo Source = d:\bar Result is False (different drives)
- Dest = \foo Source = foo (Windows) Result is False (too ambiguous to guess what this should mean)
- Dest = /foo Source = /bar AlwaysRequireSharedBaseFolder = True Result = False
- Dest = /foo Source = /bar AlwaysRequireSharedBaseFolder = False Result = True RelPath = ../foo

Version 3.2 Generated 2024-02-25 Home