Skip to content

Instantly share code, notes, and snippets.

Created February 1, 2011 20:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/806549 to your computer and use it in GitHub Desktop.
Recursive directory size count
#!perl6
sub MAIN(Str $dir where .IO.d) {
dircount($dir);
}
multi sub dircount(Str $dir where .IO.d) {
my $count = [+] dir($dir).grep(none(<. ..>)).map: { dircount("$dir/$^item") };
say "$dir: $count";
return $count;
CATCH { say "$dir: ERROR($!)"; return 0 };
}
multi sub dircount(Str $dir where .IO.f) { return 1 }
multi sub dircount(Str) { return 0 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment