#!/usr/local/bin/perl # *********************************************************************** # # * * # # * Copyright (c) 1996-1999 Scott Crevier * # # * All Rights Reserved Worldwide * # # * * # # * This program product material is the property of Scott Crevier. * # # * This program may be used and modified by anyone free of charge, * # # * as long as this copyright notice remains in tact. By using this * # # * code, you agree to indemnify Scott Crevier from any liability * # # * that might arise from its use. * # # * * # # * scott@crevier.org - Scott M. Crevier - www.crevier.org * # # *********************************************************************** # # * smcFileStats.pl v2.1 22-Dec-1998 * # # * * # # * This script prints a nice display of how many files of each * # # * type (based on the extension) exist under the indicated * # # * directory structure. * # # *********************************************************************** # # *********************************************************************** # # * Set some variables. * # # *********************************************************************** # $OTHER{'noext'} = 0; $OTHER{'directories'} = 0; $filecount = 0; $separator = "------ ---------------------\n"; $startdir = '.'; # *********************************************************************** # # * Get a list of filenames. * # # *********************************************************************** # chdir($startdir); @files = `find . -print`; # *********************************************************************** # # * Loop thru the file list, counting each extension. * # # *********************************************************************** # foreach (@files) { chomp; # Don't count the current directory. if (/^\.$/) { next; } # Count directories. if (-d) { $OTHER{'directories'}++; next; } # If the file has an extension, count it as such. Otherwise, # add it to the 'noext' count. if (/\.\w+$/) { $suffix = $_; $suffix =~ s/^.*\.(.*)$/$1/; $COUNT{$suffix}++; } else { $OTHER{'noext'}++; } } # *********************************************************************** # # * Print the results. * # # *********************************************************************** # print "COUNT EXTENSION\n"; print $separator; foreach $k (sort(keys(%COUNT))) { printf ("%5d : %s\n", $COUNT{$k}, $k); $filecount += $COUNT{$k}; } printf ("%5d : no extension\n", $OTHER{'noext'}); $filecount += $OTHER{'noext'}; print $separator; printf ("%5d : TOTAL FILES\n", $filecount); printf ("%5d : TOTAL DIRECTORIES\n", $OTHER{'directories'}); exit(0);