Link to home
Start Free TrialLog in
Avatar of ka1a
ka1a

asked on

filelistbox with full path and files from subdirectory's

I need a way to create a list (filelistbox?) of all filenames (full path, ex:'c:\windows\temp\readme.txt') that compare a given mask (with wildchars).  Also all the files (full path) in any subdirectory that compare that same given mask.  Example: 'c:\*.*' has to give a list off all the files on drive C with there full path.  Included all the hidden, system, ... files.  I need the lists to create correct backups.  I hope you understand what I mean (and need).

Thanks in advance.

Dirk.

PS sorry for my poor English.
ASKER CERTIFIED SOLUTION
Avatar of Epsylon
Epsylon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alanwhincup
alanwhincup

You could try something like this:

var
  Form1: TForm1;
  Count : Integer;

implementation

{$R *.DFM}

procedure GetAllFiles(S : string);
var
  Search : TSearchRec;
  FPath, FName : string;
begin
  FName := ExtractFileName(S);
  FPath := ExtractFilePath(S);

  if FindFirst(S, $23, Search) = 0 then
  begin
    repeat
      Form1.ListBox1.Items.Add(FPath + Search.Name);
      Inc(Count);
    until
      FindNext(Search) <> 0;
  end;

  if FindFirst(FPath + '*.*', faDirectory, Search) = 0 then
  begin
    repeat
      if ((Search.Attr and faDirectory) = faDirectory) and
         (Search.name[1] <> '.') then
      begin
        GetAllFiles(FPath + Search.Name + '\' + FName);
      end;
    until
      FindNext(Search) <> 0;
    FindClose(Search);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Dir, WildCard : string;
begin
  Screen.Cursor := crHourGlass;
  Count := 0;
  ListBox1.Items.Clear;
  Dir := Copy(Edit1.Text, 0, Length(Edit1.Text) - 3);
  WildCard := Copy(Edit1.Text, Length(Edit1.Text) - 2, 3);
  GetAllFiles(Dir + WildCard);
  if Count = 0 then
    ShowMessage('No Files Found.');
  Screen.Cursor := crDefault;
end;

Cheers,

Alan
Avatar of ka1a

ASKER

Thanks.

Your solution is excellent.  Thanks again.

Dirk.