Hello, I have searched the archives for getting filesizes with File::Recurse in Windows and found this post:

Re: Filesize counting recursive

but when I tried the code it doesn't work. Getting an error about a HASH ref:

perl mp3size.pl
Directory: ./American Music Club - San Francisco
Can't use string ("./American Music Club - San Fran") as a HASH ref while "strict refs" in use at C:/Perl/site/lib/File/Recurse.pm line 36.

Here is my code. It's supposed to read any directory containing mp3's and sum their filesizes:

use strict; use File::Recurse; my $size; my %files = Recurse(['.'], {match => '\.mp3', nomatch => '\.html$'}); foreach (sort keys %files) { my $directory = $_; print " Directory: $directory\n"; Recurse(\&sum_size, $directory, \$size); print "Total size: $size\n"; } sub sum_size { my ($file, $total_size_ref) = @_; stat($file); unless (-d $_) { $total_size_ref += -s $_; } }

In reply to getting filesize in windows by Peamasii

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.