Shaunn Johnson wrote:
>
> I'd like to get a list of files in a directory and
> also in it's subdirectory - but I don't know how
> far the subdirectory goes.
>
> I can do a directory like so:
>
> [snip]
> #my $localdir=cwd;
> my $localdir="/ddrive/db2_text/";
> chdir $localdir;
>
> opendir (DIR, $localdir) or die "can nae access D drive: $!";
> local @ARGV =  grep /\.txt$/, readdir DIR;
> closedir (DIR);
>
> [/snip]
>
> But how can I get a list of files in a subdirectory without
> having to specify all of the subdirectories as a variable?
> (I hope that made sense).
>
> It sounds like I'd have to do something like get a list of
> subdirectories first and then do a search for .txt files
> in each subdirectory?

Hi Shaunn.

This is just the sort of job that File::Find was written for.
Try this short program:

  use strict;
  use warnings;

  use File::Find;

  my $localdir = '/ddrive/db2_text';

  find(
    sub { print $File::Find::name, "\n" if /\.txt$/ },
    $localdir);

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to