I made the below work on my web server. Will just be a few changes for you to make.

#!/usr/bin/perl -T BEGIN { $| = 1; open(STDERR, ">&STDOUT"); print "Content-type: text/plain\n\n"; } my $dirfile = "/home2/jmelpubs/public_html/jimmelanson/programming/dow +nload/directory.txt"; my $log = "/home2/jmelpubs/public_html/jimmelanson/programming/downloa +d/logfile.txt"; my $global_file_count = 0; if(open(LOGFILE, ">$log")) { if(open(DIRS, '<:encoding(UTF-8)', $dirfile)) { my @directorylist = <DIRS>; close DIRS; foreach my $dir (@directorylist) { if($dir =~ /[a-zA-Z1-9]/) { chomp($dir); if ( -e "$dir/Thumbs.db") { unlink ("$dir/Thumbs.db") or print "thumbs.db $!\n +"; } opendir(READIT, $dir); my @files = readdir(READIT); closedir(READIT); my $directory_file_count = 0; foreach my $file (@files) { unless(($file eq ".") || ($file eq "..")) { $global_file_count++ unless(-d "$_/$file"); $directory_file_count++ unless(-d "$_/$file"); } } print LOGFILE "$dir : count is $directory_file_count\n +"; } } print LOGFILE "All directories count is $global_file_count\n"; close LOGFILE; } else { die "failed to open file for reading."; } close LOGFILE; } else { die "failed to open log file for writing."; } print "Final count is: $global_file_count\n"; exit;
This is what the logfile had when it was done:
/home2/jmelpubs/public_html/jimmelanson/books : count is 7 /home2/jmelpubs/public_html/jimmelanson/downloads : count is 1 /home2/jmelpubs/public_html/jimmelanson/images : count is 18 All directories count is 26
I can't post test/script download on here. I'll try to PM that to you if you want it.

In reply to Re: pushing file counts for adding by TorontoJim
in thread pushing file counts for adding by flieckster

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.