Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
132 views
in Technique[技术] by (71.8m points)

Conversion between absolute and relative paths in Delphi

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

For example:

  • 'Base' path is 'C:ProjectsProject1'
  • Relative path is '..Sharedsomefile.pas'
  • Absolute path is 'C:ProjectsSharedsomefile.pas'

I am looking for something like this:

function AbsToRel(const AbsPath, BasePath: string): string;
// '..Sharedsomefile.pas' =
//   AbsToRel('C:ProjectsSharedsomefile.pas', 'C:ProjectsProject1')  
function RelToAbs(const RelPath, BasePath: string): string;
// 'C:ProjectsSharedsomefile.pas' =
//   RelToAbs('..Sharedsomefile.pas', 'C:ProjectsProject1')  
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To convert to the absolute you have :

ExpandFileName

To have the relative path you have :

ExtractRelativePath


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...