in reply to recursive sub
#!/usr/bin/perl -w use Cwd; use strict; sub ScanTree { my $startdir = shift; # grab startdir as param passed to sub my $initdir = &cwd; # grab current working directory (see below +) chdir( $startdir ) or die "Unable to enter $startdir: $!\n"; opendir( DIR, "." ) or die "Unable to open $startdir: $!\n"; my @names = readdir( DIR ) or die "Unable to read $startdir: $!\n" +; close( DIR ); foreach my $name( @names ) { next if( $name eq "." ); next if( $name eq ".." ); if( -d $name ) { &ScanTree( $name ); next; } } # return user to saved current working directory (see above) chdir( $initdir ) or die "Unable to enter $initdir: $!\n"; } &ScanTree( "." );
Hope this is what you were looking for.
-loc
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: recursive sub
by tachyon (Chancellor) on Oct 27, 2001 at 16:00 UTC |