#!/usr/bin/perl use File::Find; my $dir = $ARGV[0] || '.'; find( sub { -f and $h{$File::Find::name} = -s }, $dir ); print "$h{$_}\t$_\n" for sort { $h{$b}<=>$h{$a} } keys %h;

For a slightly prettier version....

#!/usr/bin/perl use File::Find; die "Usage $0 <dir> <int_files_to_show>\n" if $ARGV[0] =~ m/-h/; my $dir = $ARGV[0] || '.'; my $num = $ARGV[1] || 20; # how many files to print my %h; find( sub { -f and $h{$File::Find::name} = -s }, $dir ); for ( sort { $h{$b} <=> $h{$a} } keys %h ) { printf "%s\t%s\n", add_commas($h{$_}), $_; last if --$num == 0; } sub add_commas { my ( $number ) = @_; return undef unless $number; ( $number, my $dec ) = $number =~ m!([+-]?\d+)\.?(\d*)!; return undef unless $number; $number =~ s/(\d)(?=(\d{3})+(\D|$))/$1,/g if length($number) > 3; return $dec ? "$number.$dec" : $number; }

cheers

tachyon


In reply to Re: Parsing current and sub-directories and prints out all files found from largest size to smallest by tachyon
in thread Parsing current and sub-directories and prints out all files found from largest size to smallest by TASdvlper

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.