Jump to content
Sign in to follow this  
robertjohns

File Search

Recommended Posts

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

'mytext.txt' is a file mask. A file mask does not need to contain wild cards.

Edited by dummzeuch

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×