1) I want to count numeric named files in each directory.
2) I want to capture the name of the directory those files are in
3) I want to print the directory name and the count (if any) for each
directory.
I know that all the information I want to extract is available in
File::Find.
Just having trouble seeing how to get at it when I want it.
Connecting the directory name with the file count is the rub for me.
I googled extensively but have not found this specific usage. I get
piles of examples for just counting files throughout a hierarchy.
But not giving a count and directory name of `each' directory.
I've done several hours of fumbling around and have produced several
abject failures.
Finally got something that did what I wanted.
The script below does those three things... But I have a sneaking
feeling there is some easier way to extract the info. Something
simpler that is right in front of me... but escaping me.
The test directory structure looks like this:
ls -R dir1
dir1:
111 222 333 dir2
dir1/dir2:
111 222 333 dir3
dir1/dir2/dir3:
111 222 333
ff1c:
------- ------- ---=--- ------- -------
my $usage =
"Purpose: bleh
Usage: bleh
";
my $dir;
if (! @ARGV){
warn "$usage",
"Usage tripped: line: <" . __LINE__ . ">\n",
"We need at least 1 top directory\n";
exit;
} elsif (@ARGV > 1) {
warn "$usage",
"Usage tripped: line: <" . __LINE__ . ">\n",
"Too many cmdline arguments\n";
}
$dir = shift;
if (! -d $dir) {
warn "$usage",
"Usage tripped: line: <" . __LINE__ . ">\n",
"<$dir> not found .. aborting ..\n";
exit;
}
------- ------- ---=--- ------- -------
ff1c out:
> ./ff1c
./dir1 3
./dir1/dir2 3
./dir1/dir2/dir3 3
(9) numeric files overall
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/