[Lazarus] CreateRelativePath document error.

Paul van Helden paul at planetgis.co.za
Tue Feb 9 15:57:02 CET 2010


On 2010/02/09 04:20 PM, Mattias Gärtner wrote:
>> ExpandFileName does exactly that.
>
>
> No. ExpandFilename does much more and less. It corrects \ and / to 
> path delim, expands a relative filename with the *current working 
> directory* (Get/SetCurrentDir) and it expands tilde '~' to $HOME under 
> Linux.
>
> If you want only create an absolute path from a directory and a 
> relative path use:
> AbsPath:=AppendPathDelim(BaseDir)+RelPath;
>
> This can create a file like '/usr/../lib' or '/usr/./lib' or 
> '/usr//lib', which are all valid file names, just somewhat ugly.
> To resolve '..', '.' and double path delims use TrimFilename:
>
> AbsPath:=TrimFilename(BaseDir+PathDelim+RelPath);
>
> The above three would result in '/usr/lib'.
>
> To even resolve system specials like '~' and cut trailing path delim 
> use CleanAndExpandFilename:
>
> AbsPath:=CleanAndExpandFilename(BaseDir+PathDelim+RelPath);
>
> CleanAndExpandDirectory is like CleanAndExpandFilename but appends a 
> path delim if not already there.
>
> If you even want to resolve symlinks or get the real file name (e.g. 
> OS X UTF8 normalization, case insensitive file systems) there are 
> functions for that too.
>
>
Thanks Mattias (& Michael)! What a wonderful explanation! That FExpand 
function is a beast and I didn't study it properly. I will indeed start 
using it.

Paul.




More information about the Lazarus mailing list