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
code:

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

   //iterate through the filelist
   while TempRes=0 do
   begin
      //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
            ListFilesOf(APath+'\'+SR.Name)
         else
            //otherwise we add the file to a listbox
            ListBox1.Items.Add(APath + '\' + SR.Name);

      //proceed to next file
      TempRes:=FindNext(SR);
   end;

   //Free resources
   FindClose(SR);
end; //procedure TForm1.ListFilesOf

... and this call:
ListFilesOf('e:\limbo\data\user');

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?

Regards
Toft
--
Life is for the living. I like it.
sunb...@worldonlineNOSPAM.dk
Remove NOSPAM to mail me

Sent via Deja.com http://www.deja.com/
Before you buy.

 

Re:Listing directory contents recusively


In article <82c8nr$k0...@nnrp1.deja.com>,
  Bjorn T. Madsen <sunbea...@my-deja.com> wrote:

Quote
> 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

Regards
Toft
--
Life is for the living. I like it.
sunb...@worldonlineNOSPAM.dk
Remove NOSPAM to mail me

Sent via Deja.com http://www.deja.com/
Before you buy.

Other Threads