SysUtils.ExtractRelativePath Function

Returns a relative path name, relative to a specific base directory.

Pascal
function ExtractRelativePath(const BaseName: string; const DestName: string): string; overload;
C++
AnsiString ExtractRelativePath(const AnsiString BaseName, const AnsiString DestName);

Call ExtractRelativePath to convert a fully qualified path name into a relative path name. The DestName parameter specifies file name (including path) to be converted. BaseName is the fully qualified name of the base directory to which the returned path name should be relative. BaseName may or may not include a file name, but it must include the final path delimiter.

Note: If you send it what should be a directory without the trailing backslash (c:\foo
instead of c:\foo\), the function treats foo as a file and returns undesirable results. You should correctly call it like this:

ExtractRelativePath('c:\foo\', 'c:\bar\')

so that it would return

'..\bar\'

.

ExtractRelativePath('c:\foo\', 'c:\bar')

would return the incorrect result, probably like

'..'

.