in reply to Looking for small csv files script question

Of course you can install other File::Find variants. Just search PerlMonks to see how. But why would you?

As others already showed here, it is extremely simple with File::Find. Once you are used to the idiom, you'll even start writing these quests in short versions:

use File::Find; my @files; find (sub { m/\.csv$/i && -s $_ < 5500 and push @files, $File::Find::N +ame }, "C:/Temp"); say for sort @files;

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: Looking for small csv files script question
by PerlPlay (Novice) on Dec 04, 2013 at 08:53 UTC

    Hi Tux, thanks for your short version reply. I'll have to start trying these!

    It gets trickier though, I have updated my original question.

      In sticking with the core modules so that you don't have to install any new modules, here's some untested code that is basically a modified version of what Tux provided that handles your new requirement.

      use File::Find; use File::Basename; use feature 'say'; my @files; find (sub { m/\.csv$/i && -s $_ < 5500 and push @files, $File::Find::N +ame }, "C:/Temp"); my %dirs; foreach my $file (@files) { my($filename, $directories, $suffix) = fileparse($file); $dirs{$directories}++; } my @keys = keys %dirs; @keys = sort @keys; foreach my $key (@keys) {say $key;}

      Basically, what I've done is taken the array of files that meet your criteria and then putting their path (minus filename) into a hash where the path is a key in the hash (and the value for the key is the count of files in that folder that meet your criteria). Then I'm sorting the keys and printing them out. Hopefully, this will help get your further into solving your problem.

        Hi Dasgar

        Thanks for your response - again. :-)

        Question for you though, I'm still a newbie trying to decipher shortned subs, where would I put a print statement or say in your find (sub... line?

        I'd like to actually see when it finds a suspect folder instead of waiting for it to finish before it displays the suspect folders. I have quite a number of folders and it does take a while to run.