Conversion between absolute and relative paths in Delphi

后端 未结 9 507
不思量自难忘°
不思量自难忘° 2020-11-30 01:18

Are there standard functions to perform absolute <--> relative path conversion in Delphi?

For example:

  • \'Base\' path is \'C:\\Projects\\Projec
9条回答
  •  借酒劲吻你
    2020-11-30 01:53

    I just brewed this together:

    uses
      ShLwApi;
    
    function RelToAbs(const ARelPath, ABasePath: string): string;
    begin
      SetLength(Result, MAX_PATH);
      if PathCombine(@Result[1], PChar(IncludeTrailingPathDelimiter(ABasePath)), PChar(ARelPath)) = nil then
        Result := ''
      else
        SetLength(Result, StrLen(@Result[1]));
    end;
    

    Thanks to Andreas and David for calling my attention to the Shell Path Handling Functions.

提交回复
热议问题