?
Solved

Fill a list from a dir.

Posted on 2003-02-25
17
Medium Priority
?
167 Views
Last Modified: 2010-04-04
'Folder' is a dir like c:\windows
's1' is TListBox.Items
this is the code to fill the listbox with ALL the file op the directory 'folder'

---
procedure TForm1.FillFileList(Folder: string; sl: TStrings);
var Rec : TSearchRec;
begin
 sl.Clear;
 if SysUtils.FindFirst(Folder + '*.*', faAnyFile, Rec) = 0 then
  try
    repeat
      sl.Add(Rec.Name);
    until SysUtils.FindNext(Rec) <> 0;
  finally
    SysUtils.FindClose(Rec);
  end;
end;
---
This code adds only the files from c:\windows.
How can I change the code to add also ALL the sub-directories en sub-files?
0
Comment
Question by:jurgentje
[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
  • 10
  • 6
17 Comments
 
LVL 3

Accepted Solution

by:
ILE earned 120 total points
ID: 8020924
here is the exacly correct solution
i jut tested



one button  one listbox with name s1


procedure TForm1.BitBtn1Click(Sender: TObject);
begin
 s1.items.clear;
 getalldir('c:\idapi\');
end;


procedure tform1.getalldir(s:string);
var rec :tsearchrec;
begin
if sysutils.findfirst(s + '*.*', faAnyFile, Rec)=0 then
begin
   repeat
     if (rec.name<>'.') and (rec.name<>'..') then
     begin
      s1.items.Add(s+Rec.Name);
      if rec.attr=fadirectory then getalldir(s+rec.name+'\');
     end;
   until SysUtils.FindNext(Rec) <> 0;
  sysutils.FindClose(rec);
end;



what are u thin recursion is the power4ful thing :)))


0
 
LVL 3

Expert Comment

by:ILE
ID: 8020935
100 % of working solution


but the dir is not the c:\idapi
but c:\windows\
0
 

Author Comment

by:jurgentje
ID: 8021315
Thanks, i think i can do it with this code ;)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jurgentje
ID: 8021789
I have a problem with filling the list from a CD.
He gives only the dirs and not the files in this dirs.
0
 
LVL 3

Expert Comment

by:ILE
ID: 8021891
this is because a cd files is read only
0
 
LVL 3

Expert Comment

by:ILE
ID: 8021936
if u do the code exactly how i send to you there will be working on cd

0
 

Author Comment

by:jurgentje
ID: 8021937
I already tought that was the problem, but how do I Change the code?
0
 
LVL 3

Expert Comment

by:ILE
ID: 8021978
i try the code again on the cd work perfectly
0
 

Author Comment

by:jurgentje
ID: 8022001
Not here :( He finds the subdirs, but not the file in thise dirs
0
 

Author Comment

by:jurgentje
ID: 8022014
Not here :( He finds the subdirs, but not the file in thise dirs
0
 

Author Comment

by:jurgentje
ID: 8022028
Not here :( He finds the subdirs, but not the file in thise dirs
0
 

Author Comment

by:jurgentje
ID: 8022046
Not here :( He finds the subdirs, but not the file in thise dirs
0
 

Author Comment

by:jurgentje
ID: 8022054
oeps sorry i refreshed a few times
0
 
LVL 3

Expert Comment

by:ILE
ID: 8022062
i use win98

just the ide instead of use faanyfile  try $FFFF or $FF
just curious what will be happend


replace fanayfile with $ff and try with $FFFF
0
 

Author Comment

by:jurgentje
ID: 8022088
if (rec.attr=17) or (rec.attr=18)  then

this code works
0
 

Expert Comment

by:OneSurfer
ID: 8022396
uses
 FileCtrl

var S: String;
    Rec: TSearchRec;
begin
If SelectDirectory('Select Some Directory','',S) then
If FindFirst(S+'\*.MP3', 0 , Rec) = 0 then with
  ListBox1.Items do begin
  BeginUpdate;
  Repeat
  Add(S+'\'+Rec.Name);
  Until FindNext(Rec) <> 0;
  Endupdate;
end;
{This gives complete path and file name, or just the file name(without the var)If anything, this shows a very simple way to get the Windows select directory dialog. Note: Adds about 700 pathitems in about three secs on older machine and Windows 2000}
0
 

Author Comment

by:jurgentje
ID: 8065805
OneSurfer, this code doesn't take the subdir's
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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 you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

752 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