Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to populate a TStringList with file names from a folder Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
13-Feb-03
Category
Files Operation
Language
Delphi All Versions
Views
118
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Lou Adler

I am trying to populate a TStringlist with files matching *.pas;*.dfm;*.dpr etc. 
from the current folder which is easy enough, but I also want to search sub folder 
for the same file types and keep their folder structure so that I can copy all the 
files in one go to another folder and then to CD for extra backups.

Answer:
1   
2   procedure GetFileList(const Path: string; const Extensions: string; FileList:
3     TStrings);
4   var
5     SR: TSearchRec;
6   begin
7     if FindFirst(Path + '*.*', faAnyFile, SR) = 0 then
8     try
9       repeat
10        if (SR.Attr and faDirectory) > 0 then
11        begin
12          if SR.Name[1] <> '.' then
13            GetFileList(Path + SR.Name + '\', Extensions, FileList)
14        end
15        else if Pos(UpperCase(ExtractFileExt(SR.Name)), Extensions) > 0 then
16          FileList.Add(Path + SR.Name);
17      until
18        FindNext(SR) <> 0;
19    finally
20      FindClose(SR);
21    end;
22  end;
23  
24  //Usage:
25  
26  GetFileList('c:\', '.PAS .FRM .DPR', MyStringList);


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC