Delphi File Search Recursive

21.01.2020by admin
Delphi File Search Recursive

Recursive File Search Linux

I implemented this code but again i am not able to search through the subdirectories. You can't apply a restriction to the file extension in the call to FindFirst. If you did so then directories do not get enumerated. Instead you must check for matching extension in your code. Try something like this: procedure TMyForm.FileSearch(const dirName:string);varsearchResult: TSearchRec;beginif FindFirst(dirName+'.'

, faAnyFile, searchResult)=0 then begintryrepeatif (searchResult.Attr and faDirectory)=0 then beginif SameText(ExtractFileExt(searchResult.Name), '.ini') then beginlbSearchResult.Items.Append(IncludeTrailingBackSlash(dirName)+searchResult.Name);end;end else if (searchResult.Name'.' ) and (searchResult.Name'.' ) then beginFileSearch(IncludeTrailingBackSlash(dirName)+searchResult.Name);end;until FindNext(searchResult)0finallyFindClose(searchResult);end;end;end;procedure TMyForm.FormCreate(Sender: TObject);beginFileSearch('c:windows');end. Procedure FindFilePattern(root:String;pattern:String);varSR:TSearchRec;beginroot:=IncludeTrailingPathDelimiter(root);if FindFirst(root+'.' ,faAnyFile,SR) = 0 thenbeginrepeatApplication.ProcessMessages;if ((SR.Attr and faDirectory) = SR.Attr ) and (pos('.' ,SR.Name)=0) thenFindFilePattern(root+SR.Name,pattern)elsebeginif pos(pattern,SR.Name)0 then Form1.ListBox1.Items.Add(Root+SR.Name);end;until FindNext(SR)0;end;end;procedure TForm1.Button1Click(Sender: TObject);beginFindFilePattern('C:','.exe');end;This searches recursively to all folders displaying filenames that contain a certain pattern.