Problem is $local_list[$list_count] in your print line ... @local_list only has 2 elements, but $list_count is in the range 0 ... $#dircount ... Root issue is that you need to keep track of what directory you found each file in ..

One way to solve this is just do it all at once:
foreach my $path ( @local_list ){ opendir my $dirh,$path or die "Can't open $path"; my @files = grep { /\.txt$/ } readdir($dirh); closedir($dirh) or die "Can't close $path"; foreach my $i (0..$#files){ my $file = $files[$i]; printf( '<br><b>L123 - %d - The file name: <a href="../../%s/%s">%s</a>< +/b> is <font color=red>%d</font> bytes long.<br>' . "\n\n", $i, $path, $file, $file, -s $file ; } }
Otherwise you need a data structure other than just @dircontent ...

Also of interest might be File::Find and File::Find::Rule ...

Update: a File::Find::Rule (and File::Basename) solution:
use File::Find::Rule; use File::Basename; my @files = File::Find::Rule->file() ->name( '*.txt' ) ->maxdepth(1) ->in( @local_list ) ; foreach my $i (0..$#files){ my $file = $files[$i]; printf '<br><b>L123 - %d - The file name: <a href="../../%s">%s</a></b> + is <font color=red>%d</font> bytes long.<br>' . "\n\n", $i, $file, basename($file), -s $file, ; }

In reply to Re: File Size in Directory by davidrw
in thread File Size in Directory by Anonymous Monk

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.