Are there standard functions to perform absolute <--> relative path conversion in Delphi?
For example:
- 'Base' path is
'C:\Projects\Project1\'
- Relative path is
'..\Shared\somefile.pas'
- Absolute path is
'C:\Projects\Shared\somefile.pas'
I am looking for something like this:
function AbsToRel(const AbsPath, BasePath: string): string;
// '..\Shared\somefile.pas' =
// AbsToRel('C:\Projects\Shared\somefile.pas', 'C:\Projects\Project1\')
function RelToAbs(const RelPath, BasePath: string): string;
// 'C:\Projects\Shared\somefile.pas' =
// RelToAbs('..\Shared\somefile.pas', 'C:\Projects\Project1\')
To convert to the absolute you have :
To have the relative path you have :
I just brewed this together:
Thanks to Andreas and David for calling my attention to the Shell Path Handling Functions.
Another version of RelToAbs (compatible with all Delphi XE versions).