in reply to Obtaining a list of files in a directory and subdirectory.

The classic approach is using a typeglob (perldata) globbing (glob, I/O Operators), but a simpler approach would be using the combination of opendir, readdir, and closedir to get the contents of a directory. You could also determine which of those entries are directories using the -d file test.

Update: Oops, thanks cdarke.

  • Comment on Re: Obtaining a list of files in a directory and subdirectory.

Replies are listed 'Best First'.
Re^2: Obtaining a list of files in a directory and subdirectory.
by Karger78 (Beadle) on Oct 16, 2009 at 14:46 UTC
    Thanks guys. I think i will go with the file::find::rule. However, when i try and do a simple search on a directory, i get the follwoing error: Subroutine main::find redefined at C:/Perl/site/lib/File/Find/Rule.pm line 21. Any ideas. The code is pretty simple:
    my @files = File::Find::Rule->file()->in( "c:/" );
      That warning (not an error) is thrown when you overwrite an existing subroutine, in this case you have two subroutines in your main package called "find". The File::Find::Rule module exports a subroutine named "find", so I'm guessing you've defined one as well in your code.
        Ahh ok. Thanks. Would i still use file::find even if I just want to find a directory? Or is there a different module i need to use like directory::find?