In <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
wrote
>
> "Stephen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> > I'm doing my best but having a lot of trouble understanding the
> > documentation for File::Find. After seeing a number of people being
> > yelled at for trying to reinvent the wheel by writing their own
> > functions, I'm resigned to throwing up my hands and begging for someone
> > to hold my hand through a concrete example, hopefully showing how the
> > pre\post\process functions are invoked and can be used.
> >
> > Also, I'm wondering if there's a way to implement a mechanism that times
> > the execution of the script.
> >
> > ________________________
> >
> > # Recurse a defined directory summarising folder information based on
> > # file type and then provide a way to call other functions to perform
> > # actions on any of those files.
> >
> > use strict;
> > use warnings;
> > use File::Find;
> >
> > find(\&wanted, "C:/SomeFolder");
> >
> > sub wanted {
> > my $dir_count = 0;
> > if (-d $_) {
> > print ".";
> > $dir_count++;
> >
> > # rest of code that finishes with print statements something like:
> > # "There are $file_total files in $dir_count directories."
> > # "The folder \"($folder_name)\" contains $files_in_folder .TXT files."
>
> Hi Stephen.
>
> Yes, the File::Find documentation is awful. But I shan't complain as I
> haven't offered to update it either.
>
> This sounds like a tutorial question?
>
> I'm not sure about the second part of your problem but the code below
> solves the first. See what you think.
>
> Rob
>
>
> use strict;
> use warnings;
> use File::Find;
>
> my $file_count = 0;
> my $dir_count = 0;
>
> find (\&wanted, "C:/SomeFolder");
>
> sub wanted {
> if (-d) {
> return unless /[^.]/;
> $dir_count++;
> }
> elsif (-f _) {
> $file_count++;
> }
> }
>
> printf "There are %d files in %d directories.\n",
> $file_count,
> $dir_count;
>
>
>
>
Thanks for the reply, Rob. With Perl it was love at first sight, but
the honeymoon is rough. If you could bear with me and answer the
following questions I think I'll have a better understanding of how
File::find works.
1. What is the underscore character following the -f? No laughing. <g>
2. Could you please explain how the last line works? I don't see where
the %d comes from, and how the two variables tacked on the end relate to
it.
3. Continuing with this example, how\where would I implement something
like the following:
foreach $dir(@dir_list) {
opendir (DIR, $dir);
my @files = sort ( grep(/TXT$/, readdir(DIR)) );
$number = @files; # better way to get array length?
closedir(DIR);
print "The folder $dir contains $files files.\n"
}
4. Maybe I'm restating the above question, but in addition to the
&wanted sub, File::find accommodates process, etc., as well. When/how
can these are typically used?
Thanks again.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]