Looking for a function like "FindAllDirectories" on Linux lazarus / 32-Linux ---------------------------------------------------------------------- DelphiFreak · 2013-07-24 16:07 Hello NG, I have function to search for directories with Searchmask "_SearchMask" in folder "_path". This method run's nice on windows, but on linux im getting a problem with folder /dev. It never exit's. I also tried the method "FindAllFiles" but I think it has the same problem. Does someone have a working routine to search for folders? Thank you. Code: [Select]procedure AllDirectoriesOfPath(const _Path:string;_SearchMask: string;_DirList:TStrings;_StatusBar:TStatusBar); // get all directories of path <_path> into the Dirlist. var   _SearchRec : TSearchRec;   function AddToList(const _Rec : TSearchRec;_searchmask:string):boolean;   begin     result:=false;     if _Rec.Attr and faDirectory<>faDirectory then exit;  // we only want directories here     if _Rec.name='' then exit;                            // empty name is not allowed.     if pos('.',_Rec.name)=1 then exit;                    // '..' and '.' we also don't want in the list.     if _DirList.IndexOf(IncludeTrailingPathDelimiter(_Path)+_Rec.Name)>-1 then exit;          // check if the entry is not already in the list.     if pos(_searchmask,lowercase(_Rec.Name))<>0 then _DirList.add(IncludeTrailingPathDelimiter(_Path)+_Rec.Name); // add it.     result:=true;   end; begin   if not assigned(_DirList) then exit;   _SearchMask:=lowercase(_SearchMask);   try     if not SysUtils.FindFirst(IncludeTrailingPathDelimiter(_Path)+'*', faDirectory , _SearchRec) = 0 then exit;     AddToList(_SearchRec,_SearchMask);     while SysUtils.FindNext(_SearchRec) = 0 do begin       if not AddToList(_SearchRec,_searchMask) then continue;       _StatusBar.simpletext:=IncludeTrailingPathDelimiter(_Path)+_Sear chRec.Name;       AllDirectoriesOfPath(IncludeTrailingPathDelimiter(_Path)+_Search Rec.Name,_SearchMask,_DirList,_StatusBar);       Application.ProcessMessages;     end;   finally     SysUtils.FindClose(_SearchRec);   end; end; ---------------------------------------------------------------------- Leledumbo · 2013-07-24 17:22 Perhaps you're caught in a symlink that points to one of its ancestor, I don't really remember what /dev contains though. ---------------------------------------------------------------------- DelphiFreak · 2013-07-24 17:31 Thank you for your answer. I added Code: [Select]if _Rec.Attr and faSymLink=faSymLink then exit; but it did not change anything. ---------------------------------------------------------------------- Leledumbo · 2013-07-24 17:54 Try printing the filepath on each found, you should see whether the path goes up and down or just down consistently ---------------------------------------------------------------------- DelphiFreak · 2013-07-24 18:02 Hi, now it works. After adding Code: [Select] or fasymlink to the findfirst statement, it suddenly worked. Final version looks now like this: Code: [Select]procedure AllDirectoriesOfPath(const _Path:string;_SearchMask: string;_DirList:TStrings;_StatusBar:TStatusBar); // get all directories of path <_path> into the Dirlist. var   _SearchRec : TSearchRec;   function AddToList(const _Rec : TSearchRec;_searchmask:string):boolean;   begin     result:=false;     if _Rec.Attr and faDirectory<>faDirectory then exit;  // we only want directories here     if _Rec.Attr and faSymLink=faSymLink then exit;     if _Rec.name='' then exit;                            // empty name is not allowed.     if pos('.',_Rec.name)=1 then exit;                    // '..' and '.' we also don't want in the list.     if _DirList.IndexOf(IncludeTrailingPathDelimiter(_Path)+_Rec.Name)>-1 then exit;          // check if the entry is not already in the list.     if pos(_searchmask,_Rec.Name)<>0 then _DirList.add(IncludeTrailingPathDelimiter(_Path)+_Rec.Name); // add it.     result:=true;   end; begin   if not assigned(_DirList) then exit;   try     if not SysUtils.FindFirst(IncludeTrailingPathDelimiter(_Path)+'*', faDirectory or fasymlink , _SearchRec) = 0 then exit;     AddToList(_SearchRec,_SearchMask);     while SysUtils.FindNext(_SearchRec) = 0 do begin       if not AddToList(_SearchRec,_searchMask) then continue;       _StatusBar.simpletext:=IncludeTrailingPathDelimiter(_Path)+_Sear chRec.Name;       AllDirectoriesOfPath(IncludeTrailingPathDelimiter(_Path)+_Search Rec.Name,_SearchMask,_DirList,_StatusBar);       Application.ProcessMessages;     end;   finally     SysUtils.FindClose(_SearchRec);   end; end; ---------------------------------------------------------------------- Bart · 2013-07-24 21:39 By doing so (or faSymlink) you tell FindFirst/FindNext not to follow symlinks. Bart