Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

After a few trials, I was able to do what I want using the file::find module and a few regex. The below code gives me the number files fore each unique extentions in a directory.

Now I am trying to find the cumulative sizes of each type of file in the directory. For example if there are 50 Html files, I am trying to find the sum of the size of all 50 HTML files and likewise for every extention that my array @exts contains.

I tried using file::find::rule->..->name( foreach @ext ) to parse through and find the size, but couldnt get it right. Could someone pls guide?thanks

use strict; use warnings; use feature "switch"; use File::Basename; use File::Find; use Data::Dumper; $Data::Dumper::Sortkeys=1; my $start_dir = "F:/"; my @exts; find (\&print_all_directories, "$start_dir"); print "Parsing\n"; sub print_all_directories { return if -d; my $full_dir_path = $File::Find::name; my ($ext) = $full_dir_path =~ /(\.[^.]+)$/; my ($name,$path,$suffix) = fileparse($full_dir_path,qr"\..[^.]*$") +; push (@exts, $suffix); } my %counts; $counts{$_}++ for @exts; #print Dumper(\%counts); foreach my $name (sort {$counts{$a} <=> $counts{$b}} keys %counts) { printf "%s %s\n", $name, $counts{$name}; }

In reply to Re^2: Perl Directory file extension stats. by sidsinha
in thread Perl Directory file extension stats. by sidsinha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-03-19 10:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found