Solved

create a filelist

Posted on 2001-06-14
4
155 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
ID: 6190150
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
ID: 6190210
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
ID: 6190212
Thanks, I'll test it.
0
 

Author Comment

by:tzigan
ID: 6190286
Great, Thanks
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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

807 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