DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Howmany
#!/usr/bin/perl
#==========================================================================================
# howmany -- a tool for determining how many different types of files are in a folder
#------------------------------------------------------------------------------------------
# Author: Elliot Winkler <elliot.winkler@gmail.com>
# Created: 11 Mar 2008
#==========================================================================================
my $dir = $ARGV[0] || ".";
my $cmd = "find $dir";
my @listing = sort grep { $_ } split /\n/, `$cmd`;
my %exts;
for (@listing) {
my($ext) = /\.([a-z]+)$/;
next unless $ext;
$exts{lc $ext}++;
}
for (sort keys %exts) {
print uc($_).": ".$exts{$_}."\n";
}
Example: <pre> $ cd ~/docs $ howmany CSV: 3 DOC: 1 KEY: 1 PUB: 1 SQL: 1 TEXT: 1 TXT: 9 XCF: 2 XLS: 1 ZIP: 1 $ howmany ~/docs CSV: 3 DOC: 1 KEY: 1 PUB: 1 SQL: 1 TEXT: 1 TXT: 9 XCF: 2 XLS: 1 ZIP: 1 </pre> <b>Note:</b> This only works on Linux/Unix, because it relies on a Linux/Unix-only command to pull up the list of files. A future update may include support for Windows, though it would be pretty easy to find out how to fix it.





