Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All

can someone PLEASE give me a example of how can use File::find to obtain all file names and their paths from a given folder using File::ind module? Thanks

Any one knows the URL to O'rielly cookbook (the free on line documentation)?

Thanks

Replies are listed 'Best First'.
Re: File Find Dir and name
by bart (Canon) on Jul 11, 2005 at 14:02 UTC
    use File::Find; use Cwd; $\ = "\n"; my @files; find sub { print $File::Find::name if -f; # or: push @files, $File::Find::name if -f; }, @ARGV ? @ARGV : cwd; # pass dir(s) as command line argument, or us +e current directory
Re: File Find Dir and name
by jbrugger (Parson) on Jul 11, 2005 at 14:03 UTC
    untested fast example:
    use File::Find; my @files; find( sub { push (@files, "$File::Find::dir/$_"); }, '/var/www/dir', '/var/www/anotherdir', );
    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
Re: File Find Dir and name
by Joost (Canon) on Jul 11, 2005 at 14:03 UTC
Re: File Find Dir and name
by marto (Cardinal) on Jul 11, 2005 at 14:03 UTC
    Hi,

    I think it would be worth while to read the documentation for File::Find.

    Hope this helps

    Martin
      Had if there been one example in the docs like the above I wouldn't have bothered you....Thanks.

      I was intereseted to see the use of File::Find::Name and File::Fine::Dir

      Thanks
        I agree, wish the documentation had this. Had the same problem a while ago and it took me way longer than it should have to do such an obvious thing.
Re: File Find Dir and name
by sh1tn (Priest) on Jul 11, 2005 at 14:16 UTC
    cli$ perl -MFile::Find -e 'find( sub{ print $File::Find::name,$/ }, ". +" )'