Solved

How to do WildCard search in Delphi

Posted on 2003-12-08
4
806 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 9902509
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
ID: 10368200
kretzschmar thank you!
i tried it and it worked, hope the question author is about to find this out ;-).
Best regards...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

756 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