Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to count files in a directory w/PERL
02-12-2019, 10:25 PM
Post: #1
How to count files in a directory w/PERL
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/



Visit this user's website Find all posts by this user
Quote this message in a reply
02-13-2019, 09:34 PM
Post: #2
RE: How to count files in a directory w/PERL
Well, that's interesting......thanks...
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)