TandemTables Forum

Full Version: How to count files in a directory w/PERL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
To find the total number of files (and subdirectories) in any directory, just include this snippet in any cgi file in that directory.

$dirt = './';
@files = <$dirt/*>;
$count = $#files + 1;

$#files is the count of the last file. Since operating systems count from zero the last file number requires a plus 1 to achieve the actual total.

Here is a simple page to demonstrate:
http://jawjahboy.com/scripts/perl/filecount.cgi

Here is code that creates the page:
http://jawjahboy.com/scripts/perl/filecount.txt

Here is a very involved application using this snippet to show the count of my smiley and avatar images:
http://jawjahboy.com/Graphics/smileys-av...age-count/
Well, that's interesting......thanks...
Reference URL's