
monocle
User
May 19, 2000, 3:54 PM
Post #3 of 6
(2547 views)
|
This could be made quicker if you just get the number of elements in the @linez array, but this will allow you to only count a certain file type (i.e. gif or jpg) <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> #!/usr/bin/perl # Get the name of directory to count $dir_to_count = "$ENV{'QUERY_STRING'}"; # Read contents of your directory opendir(RID,"$dir_to_count") | | print "cant $!"; flock(2, RID); @linez = grep(/./,readdir(RID)); flock(8, RID); close(RID); # Initialize various extention counters $html = "0"; $txt = "0"; $gif = "0"; $jpg = "0"; $sound = "0"; $direcs = "0"; $misc = "0"; # Look at each element of the directory and count them by f1le type foreach $struck (@linez) { if (!(-d $struck)) { if ($struck =~ /\.htm$/i) { $html++; } elsif ($struck =~ /\.html$/i) { $html++; } elsif ($struck =~ /\.txt$/i) { $txt++; } elsif ($struck =~ /\.gif$/i) { $gif++; } elsif ($struck =~ /\.jpg$/i) { $jpg++; } elsif ($struck =~ /\.wav$/i) { $sound++; } elsif ($struck =~ /\.au$/i) { $sound++; } else { $misc++; } } } # Add all the file types up or not --- this is up to you $file_total = ($html + $txt + $gif + $jpg + $sound); print "Content-type: text/html\n\n"; print $file_total; </pre><HR></BLOCKQUOTE> call it like this: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> <html> <body> Gallery 1 (<!--#include virtual="/cgi-bin/count_files.cgi?path_and_name_of_directory_to_count" --> images) </body> </html> </pre><HR></BLOCKQUOTE> I just tested this and it should will work. Monocle BTW - This is free of charge - If you feel like it was worth it, you can thank me by giveing my music a good listen. http://www.mp3.com/monocle [This message has been edited by monocle (edited 05-19-2000).]
|