Scanning all files on MacOS X lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- Julius · 2012-03-09 12:28 Hello, currently I have a request to build a file scanner for Mac. It should check all files and list the ones that mach some criteria. Also the search has to be interactive - the user should see what file is being checked and the list of currently found files. On MS Windows this is easy - I just search for files in top directory then recursively search all it's subdirectories and so on.. (using SysUtils.FindFirst SysUtils.FindNext) On Mac this approach is not working as there can be (and are) mounted directories like /Volumes/System that links to /. Using the MS Win approach puts me into the never ending loop. Any ideas? Thank You in advance! ---------------------------------------------------------------------- Jonas Maebe · 2012-03-09 12:34 You can check whether a found file/directory has the faSymLink attribute set, and if so ignore it. ---------------------------------------------------------------------- Julius · 2012-03-09 14:15 Thank You, Jonas, for the quick response. I tried implementing faSymLink checking but with no positive results... Code: [Select]procedure TForm1.Button2Click(Sender: TObject); var _SearchRec: TSearchRec;   _FileName: String;   _Dir: String;   _SymLink: String; begin   _Dir := '/Volumes/';   if FileUtil.FindFirstUTF8(IncludeTrailingPathDelimiter(_Dir)+'*', faAnyFile , _SearchRec) = 0 then   repeat     _FileName := IncludeTrailingPathDelimiter(_Dir)+_SearchRec.Name;     if ((_SearchRec.Attr and faSymLink) = faSymLink) then       _SymLink := ' SymLink '     else       _SymLink := '';     Memo1.Lines.Add(_FileName +_SymLink);   until (FileUtil.FindNextUTF8(_SearchRec) <> 0);   FindCloseUTF8(_SearchRec); end;  This outputs me subdirs of /Volumes/ but non of them is marked SymLink. Any thoughts  why ? Lazarus 0.9.30 FPC 2.4.2 OS: Snow Leopard ( 10.6.8 ) ---------------------------------------------------------------------- Jonas Maebe · 2012-03-09 14:49 You have to add faSymlink also to the search criteria (so "faAnyFile or faSymlink"), otherwise FindFirst/FindNext will immediately follow symbolic links and return the attributes from the link destination. The reason is that otherwise the behaviour of existing programs would have changed after support for faSymlink was added (since they previously also got the information about the link destination). ---------------------------------------------------------------------- Julius · 2012-03-09 15:34 Thank You!