Solved

How to do WildCard search in Delphi

Posted on 2003-12-08
4
792 Views
Last Modified: 2010-05-18
hi all,

how to do a wildcard file seacrh in Delphi
i am workin gwith D7

i have try
FindFirst, FileSearch, but fails...

B.Regards
0
Comment
Question by:lamtl354
4 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
Comment Utility
a sample,
which can use multiple filemasks

unit filesearch_with_masks_u;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    ListBox1: TListBox;
    Button1: TButton;
    CheckBox1: TCheckBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses filectrl; //just for selectdirectory

procedure FindFile(APath : string;
                  IncludeSubDirs : Boolean;
                  FileMasks : TStrings;
                  ResultList : Tstrings
                  );
var
  srec : TSearchRec;
  Path, FileName : String;
  i : integer;
begin
  path := APath;
  if path[length(path)] <> '\' then
    path := path + '\';

  if not assigned(FileMasks) then
    raise exception.Create('No Masks given');
  if not assigned(ResultList) then
    raise exception.Create('No ResultContainer given');
  for i := 0 to filemasks.Count - 1 do
  begin
  // CurrentDirectory
    if findfirst(Path+filemasks[i],faanyfile,srec) = 0 then
    begin
    repeat
      If Not(srec.attr and fadirectory > 0) then
      begin
        ResultList.Add(Path+SRec.Name)
      end;
    Until findnext(srec) <> 0;
    end;
    FindClose(SRec);
    { SubDirectories }
    If IncludeSubDirs then
    begin
    if FindFirst(Path+'*.*',FaAnyFile,Srec) = 0 then
    begin
      repeat
        // StartRecursion
        if not(Srec.Name[1] = '.') and (srec.attr and fadirectory > 0)then
          FindFile(Path + Srec.Name + '\' + FileName,IncludeSubDirs,FileMasks,ResultList)
      Until findnext(srec) <> 0;
    end;
    FindClose(SRec);
    end;
  end;
end;


//usage sample
procedure TForm1.Button1Click(Sender: TObject);
var path : String;
begin
  if selectDirectory('Select Directory','',path) then
  begin
    listbox1.Items.Clear;
    findfile(path,checkbox1.Checked,memo1.lines,listbox1.items);
    showmessage(inttostr(listbox1.Items.Count)+' files found');
  end;
end;

end.

meikl ;-)
0
 

Expert Comment

by:bbh2k3
Comment Utility
kretzschmar thank you!
i tried it and it worked, hope the question author is about to find this out ;-).
Best regards...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now