Solved

create a filelist

Posted on 2001-06-14
4
157 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Spellcheck in Webbrowser 1 76
delphi parse string to params 3 172
Base1 Encode/Decode 3 98
shape, triangle, dbctrlgrid 3 44
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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