?
Solved

create a filelist

Posted on 2001-06-14
4
Medium Priority
?
159 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
[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
  • 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 800 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

770 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