Bryan R Harris wrote:
>
> I have a large directory tree that I'd like to build index files for,
> essentially an
>
> ls > index.txt
>
> in each directory in the tree. Obviously I'm having trouble figuring it
> out. =)
>
> I've tried the following:
>
> use File::Find;
> sub process_file {
> if (-d) {
> $tmp = `ls $_`;
> open(OFILE, "> index.txt") || die ("Couldn't open index.txt: $!\n");
> print OFILE $tmp;
> close(OFILE);
> }
> }
> find(\&process_file, @ARGV);
> print "\n";
>
> But it misses the deepest level of directories. Is there an established
> way of doing this kind of thing?
This should do what you want:
use File::Find;
my %dirs;
find( sub { push @{$dirs{$File::Find::dir}}, "$_\n" unless /^\.\.?$/ }, @ARGV );
for my $dir ( keys %dirs ) {
open OFILE, "> $dir/index.txt" or warn "Cannot open $dir/index.txt: $!";
print OFILE @{$dirs{$dir}};
close OFILE;
}
__END__
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]