robertjohns 0 Posted May 24, 2023 I am using Delphi 10.2 Is it possible to search Directories and Sub-Directories by File Name instead File Mask like mytext.txt instead of *.txt So far I tried the following function but it does not work by filename it works with file extension another issue with this function is that it does not list the complete searched files from Windows\system32\drivers\ procedure FindFilePattern(root:String;pattern:String); var SR:TSearchRec; begin root:=IncludeTrailingPathDelimiter(root); if FindFirst(root+'*',faAnyFile,SR) = 0 then begin repeat Application.ProcessMessages; if ((SR.Attr and faDirectory) = SR.Attr ) and (pos('.',SR.Name)=0) then FindFilePattern(root+SR.Name,pattern) else begin if 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); begin FindFilePattern('C:\','.sys'); end; Share this post Link to post
dummzeuch 1505 Posted May 24, 2023 (edited) 'mytext.txt' is a file mask. A file mask does not need to contain wild cards. Edited May 24, 2023 by dummzeuch Share this post Link to post
mvanrijnen 123 Posted May 24, 2023 Why not use (in unit System.IOUtils), TDirectory.GetFiles(), see: System.IOUtils.TDirectory.GetFiles - RAD Studio API Documentation (embarcadero.com) 1 Share this post Link to post