Never been to DZone Snippets before?

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

About this user

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

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:

$ 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


Note: 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.
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS