Avatar of jurgentje
jurgentje
 asked on

Fill a list from a dir.

'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?
Delphi

Avatar of undefined
Last Comment
jurgentje

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ILE

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ILE

100 % of working solution


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

ASKER
Thanks, i think i can do it with this code ;)
jurgentje

ASKER
I have a problem with filling the list from a CD.
He gives only the dirs and not the files in this dirs.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ILE

this is because a cd files is read only
ILE

if u do the code exactly how i send to you there will be working on cd

jurgentje

ASKER
I already tought that was the problem, but how do I Change the code?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ILE

i try the code again on the cd work perfectly
jurgentje

ASKER
Not here :( He finds the subdirs, but not the file in thise dirs
jurgentje

ASKER
Not here :( He finds the subdirs, but not the file in thise dirs
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
jurgentje

ASKER
Not here :( He finds the subdirs, but not the file in thise dirs
jurgentje

ASKER
Not here :( He finds the subdirs, but not the file in thise dirs
jurgentje

ASKER
oeps sorry i refreshed a few times
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ILE

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
jurgentje

ASKER
if (rec.attr=17) or (rec.attr=18)  then

this code works
OneSurfer

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}
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
jurgentje

ASKER
OneSurfer, this code doesn't take the subdir's