in reply to Re: Reading entire subfolder tree into an array
in thread Reading entire subfolder tree into an array

Actually I strongly advise using File::Find instead. There's too much to think of when you roll your own: what happens if you run into symlinks for example? Perl standard and CPAN modules for seemingly simple tasks are there for a reason.

Makeshifts last the longest.

  • Comment on Re^2: Reading entire subfolder tree into an array

Replies are listed 'Best First'.
Re: Re: Re: Reading entire subfolder tree into an array
by sdyates (Scribe) on May 28, 2002 at 19:38 UTC

    Based on all your input, I have spent the last few hours readin up on find::file and believe it is the best way to go. However, i do have one remaining question.

    First, herre is my code I have come up with:

    use File::Find; finddepth (\&RetrieveAll, "c:\\fpx"); sub RetrieveAll { push (@list,$_,"\n"); }

    How do I get $_ to include the absolute path of the file? $_ lists the folder name, then all files within it... i'd rather have the absolute path.

    Is this simple?

    Please advise
    Simon
      perldoc File::Find says:
      The wanted() function does whatever verifications you want.
      $File::Find::dir contains the current directory name, and $_ the current filename within that directory. $File::Find::name contains the complete pathname to the file.
      Btw - what's that "\n" do there in the push()? :-)
      ____________

      Makeshifts last the longest.
      Hi Simon, you just have to use the module variable $File::Find::name instead of $_. It's as easy as that. So your code will look like

      use File::Find; finddepth (\&RetrieveAll, "c:\\fpx"); sub RetrieveAll { push (@list,$File::Find::name,"\n"); }

      HTH

      weini