Dan Jones wrote:
> As near as I can tell, Find::Find was not designed for this. It's only
> capable of running a command on each file, not processing files and file
> names in batches as I'm trying to do. Am I missing some of Find::Finds
> capabilities?
Yes, you're missing the 'preprocess' and 'postprocess' hooks that I added
to File::Find back in 2000.
Here's how to get all the file names and then process as a single batch:
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use vars qw/*name/;
*name = *File::Find::name;
our(@files,@dirs);
find( sub {if(-d $_){push @dirs,$name}else{push @files,$name}}, 'Olympus');
print "Directories: @dirs\nFiles: @files\n";
Here's how to process the beginning and the end of directories, recursively.
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use vars qw/*name *dir/;
*name = *File::Find::name;
*dir = *File::Find::dir;
my %options = (
wanted => \&wanted,
preprocess => \&pre,
postprocess => \&post,
);
our %info;
find \%options, qw(Olympus Canon); # Subdirectories full of pictures
print "$info{$_}\n\n" for sort keys %info;
exit;
sub pre { # Called before entering a directory
$info{$dir} = "\t DIR: $dir\n";
sort @_; # Pre-process directory entries by sorting them
}
sub wanted { # Called for each directory entry
$info{$dir} .= (-d $_) ? "Dir: $_\n" : "File: $_\n";
}
sub post { # Post-process dir by appending END
$info{$dir} .= "\t END: $dir\n";
}
-Joe
P.S. Don't post to comp.lang.perl; post to comp.lang.perl.misc instead.
|