Conversion between absolute and relative paths in Delphi

后端 未结 9 459
不思量自难忘°
不思量自难忘° 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:56

    To convert to the absolute you have :

    ExpandFileName

    To have the relative path you have :

    ExtractRelativePath

    0 讨论(0)
  • 2020-11-30 01:58
    TPath.Combine(S1, S2);
    

    Should be available since Delphi XE.

    0 讨论(0)
  • 2020-11-30 01:58

    I am not too certain if this is still needed after 2+ years, but here is a way to get the Relative to Absolute (As for Absolute to Relative I would suggest philnext's ExtractRelativePath answer):

    Unit: IOUtils

    Parent: TPath

    function GetFullPath(const BasePath: string): string;
    

    It will return the full, absolute path for a given relative path. If the given path is already absolute, it will just return it as is.

    Here is the link at Embarcadero: Get Full Path

    And here is a link for Path Manipulation Routines

    0 讨论(0)
提交回复
热议问题