[Lazarus] CreateRelativePath document error.

Mattias Gärtner nc-gaertnma at netcologne.de
Tue Feb 9 16:28:12 CET 2010


Zitat von Paul van Helden <paul at planetgis.co.za>:

>
> 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'.

/usr/../lib is of course resolved to /lib, not /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.

Where is the file tutorial on the wiki?

Mattias






More information about the Lazarus mailing list