[fpc-pascal] cross os symbolic link handling

Marc Santhoff M.Santhoff at t-online.de
Fri Oct 31 20:59:21 CET 2008


Am Freitag, den 31.10.2008, 18:43 +0100 schrieb Michael Van Canneyt:
> 
> On Fri, 31 Oct 2008, Marc Santhoff wrote:
> 
> > Hi,
> > 
> > is there any function or set of functions for handling symbolic links
> > inside the file system at an os independant level in fpcs libraries?
> > 
> > Unix-like systems have soft symlinks (Linux, FreeBSD), Windows has .lnk
> > files upt to XP and AFAIR Windows Vista has some other stuff I don't
> > know about yet.
> > 
> > What I'd need would be sth. like:
> > 
> > function IsLink(<filehandle or name>): boolean;
> > function GetLinkTarget(<filehandle or name>): <filehandle or name>;
> > 
> > Any help on this topic is welcome ... ;)
> 
> Fpc 2.3.1 supports faSymLink in the FindFirst/FindNext series of calls.
> If it is included in the attributes, then symbolic links are included as 
> symbolic links and not as the file/dir they refer to.

That's the key part of the information, and good news to me. :)

> This works cross-platform. So you could do something like
> 
> function IsLink(AFileName : string): boolean;
> 
> Var
>   Info : TSearchRec;
> 
> begin
>   Result:=FindFirst(AFileName,faSymLink,info)=0;
>   If Result then
>     begin
>     Result:=(info.attr and faSymLink)=faSymLink;
>     FindClose(info);
>     end;
> end;

That part is easily solvable if writing one function per od type is not
necessary.

Many thanks,
Marc





More information about the fpc-pascal mailing list