Recent

Author Topic: work with symlink  (Read 2274 times)

berghem

  • Jr. Member
  • **
  • Posts: 60
work with symlink
« on: January 14, 2019, 11:08:24 am »
Hi
In my program I get the recent file of Windons, but in C:\Users\MyUser\AppData\Roaming\Microsoft\Windows\Recent there are only symlink. Is There a function for get the real path of file?

Thanks

Wallaby

  • Jr. Member
  • **
  • Posts: 79
Re: work with symlink
« Reply #1 on: January 14, 2019, 11:15:56 am »
FSCTL_GET_REPARSE_POINT or GetFinalPathNameByHandle

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: work with symlink
« Reply #2 on: January 14, 2019, 03:05:54 pm »
FPC trunk also has FileGetSymLinkTarget, though that function is currently only implemented for Windows (in your case that would be enough however ;) ).

berghem

  • Jr. Member
  • **
  • Posts: 60
Re: work with symlink
« Reply #3 on: January 16, 2019, 08:36:51 am »
I saw on Google an example with FileGetSymLinkTarget, but I don't know wich unit I gave to import in my file....
I looked for with Google but i saw only delphi example and it use SysUtils, but not lazarus

This is my code

procedure TForm1.GetInfo;
var
  SymLinkRec:TSymLinkRec;
begin
  Memo1.Clear;
  If FindFirst ('C:\Users\MyUsers\AppData\Roaming\Microsoft\Windows\Recent\*',faAnyFile or fasymlink ,Info)=0 then
  begin
    Repeat
      With Info do
        begin
        If (Attr and fasymlink) = fasymlink then

           Memo1.Lines.Add('found symlink: ' + info.name)
        else
           begin
            *FileGetSymLinkTarget('C:\Users\MyUsers\AppData\Roaming\Microsoft\Windows\Recent\' + info.name,SymLinkRec);
           Memo1.Lines.Add(SymLinkRec.Name);
           end;
        end;
    Until FindNext(info)<>0;
    end;
  FindClose(Info);
end;

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: work with symlink
« Reply #4 on: January 16, 2019, 09:32:30 am »
With FPC 3.3.1 this should work. Lazarus ships by default with FPC 3.0.4 however.

berghem

  • Jr. Member
  • **
  • Posts: 60
Re: work with symlink
« Reply #5 on: January 16, 2019, 11:08:53 am »
Can you tell me wich unit I have to import please?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: work with symlink
« Reply #6 on: January 17, 2019, 12:47:11 pm »
Same as in Delphi: SysUtils

 

TinyPortal © 2005-2018