How to count files in a directory w/PERL - Printable Version +- TandemTables Forum (http://tandemtables.com/forum) +-- Forum: Tandem Trends (/forumdisplay.php?fid=1) +--- Forum: Code (/forumdisplay.php?fid=3) +--- Thread: How to count files in a directory w/PERL (/showthread.php?tid=16650) |
How to count files in a directory w/PERL - jawjahboy - 02-12-2019 10:25 PM 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-avatars/image-count/ RE: How to count files in a directory w/PERL - Sally - 02-13-2019 09:34 PM Well, that's interesting......thanks... |