Board index » delphi » Listing directory contents recusively

Listing directory contents recusively

Hi all

While still wondering about my network prob. (see other post), I
decided to enter another avenue of my program.

I need to list the contents of a user specified directory (including
sub directories), which should be pretty straight forward using this

procedure TForm1.ListFilesOf(APath:string);
var   TempRes :Integer; //stores our temporary result
      SR      :TSearchRec; //stores info about current file
   //Find the first file and set search options
   TempRes:=FindFirst(APath+'\*.*',faAnyFile, SR);

   //iterate through the filelist
   while TempRes=0 do
      //lets make sure we won't select the previous directory
      if (SR.Name<>'.') and (SR.Name<>'..') then
         //if we have found a directory
         if (SR.Attr and faDirectory > 0) then
            //we search this directory recursively
            //otherwise we add the file to a listbox
            ListBox1.Items.Add(APath + '\' + SR.Name);

      //proceed to next file

   //Free resources
end; //procedure TForm1.ListFilesOf

... and this call:

Now, the funny thing about this that it runs perfectly!
So what might my problem be then? If I change this line:
TempRes:=FindFirst(APath+'\*.*',faAnyFile, SR);

... into this one:
TempRes:=FindFirst(APath+'\*.dat',faAnyFile, SR);

... thus using just a valid wildcard as *.*, the recursive call
suddenly spawns problems.

I suspect it has something to do with the fact that FindFirst
dynamically aquires some memory that (maybe) behaves strange in a
recursive call, but it just sounds a little weak that a change from one
valid wildcard to the next should ruin the show.

What gives? Anyone?

Life is for the living. I like it.
Remove NOSPAM to mail me

Sent via
Before you buy.


Re:Listing directory contents recusively

In article <82c8nr$>,
  Bjorn T. Madsen <> wrote:

> Hi all
> [continuing to babble about problem not quite thought through]

But of course! :)
Having a *.dat will never reveal the directories, thus never recurse
down the directory tree... he he

Life is for the living. I like it.
Remove NOSPAM to mail me

Sent via
Before you buy.

Other Threads