Solved

create a filelist

Posted on 2001-06-14
4
151 Views
Last Modified: 2010-04-06
Using Delphi 5
The prog must run under W2k and W98.

I have a directory c:\Templates.
There are subdirectories with files.
i.e.
c:\Templates\SubDir1\file1
c:\Templates\SubDir1\file2
c:\Templates\SubDir1\file3
c:\Templates\SubDir1\file4
c:\Templates\SubDir2\filex
c:\Templates\SubDir2\filey
and so on.
(not a deeper structure)

i need a list in a memo or so with all these Files and the complete path when i start my program.


0
Comment
Question by:tzigan
  • 2
4 Comments
 
LVL 17

Expert Comment

by:inthe
Comment Utility
hi,

is this ok:

Regards Barry

procedure GatherFiles(Const Lines: TStrings; Const Dir,Match: String);
var
  Rec: TSearchRec;
  Found: Integer;
Begin
  Found:= FindFirst(Dir+'\'+Match, faAnyFile, Rec);
  While Found = 0 do
  begin
    If (Rec.Attr AND faDirectory) = 0 Then Lines.Add(Dir+'\'+Rec.Name);
    Found := FindNext(Rec);
  End;
  FindClose(Rec);
  Found:= FindFirst(Dir+'\*.*', faAnyFile, Rec);
  While Found = 0 do
  begin
    If ((Rec.Attr AND faDirectory)>0) AND
       (Rec.Name<>'.') AND
       (Rec.Name<>'..') Then GatherFiles(Lines,Dir+'\'+Rec.Name,Match);
    Found := FindNext(Rec);
  End;
  FindClose(Rec);
End;

procedure TForm1.Button1Click(Sender: TObject);
begin
  memo1.Clear;
  GatherFiles(memo1.lines,'C:\mysql','*.*');
end;
0
 
LVL 2

Accepted Solution

by:
bugroger earned 200 total points
Comment Utility
Here is an example:

These two lines must be put into the
OnCreate - event from your form.

 Memo1.Clear; //is not necessary
 GetFiles('c:\templates', Memo1); //get all files in "DIR"


Procedure GetFiles(Dir : string; Memo : TMemo);
 Procedure _GetFiles(StartDir : string);
 var
  SR : tSearchRec;
  ERG : integer;
  s   : string;

 begin
  IF StartDir[Length(StartDir)]<>'\' then StartDir := StartDir + '\';

  ERG := findfirst(StartDir+'*.*', faANYFILE, SR);
  While (ERG = 0) do
  begin
   //IF it a directory then step in
   IF (SR.Attr and faDirectory > 0)and(SR.Name[1] <> '.') then _GetFiles(StartDir + SR.Name)
    else
   //else
   IF (SR.Name[1] <> '.') then
   Begin
    Memo.Lines.Add(StartDir + SR.Name);
   End;
   ERG := FindNext(SR);
   Application.ProcessMessages;
  end;
  FindClose(SR);
 end;
Begin
 _GetFiles(Dir);
End;

0
 

Author Comment

by:tzigan
Comment Utility
Thanks, I'll test it.
0
 

Author Comment

by:tzigan
Comment Utility
Great, Thanks
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

13 Experts available now in Live!

Get 1:1 Help Now