Hello,
  How about:

use strict;

my $dir='c:/test';
my $match='^AB';

opendir(D,$dir) or die "Can't open $dir: $!\n";
my @files=readdir(D);
close(D);

my $totalsize=0;
for(@files) {
  next if(!/$match/);
  $totalsize+=(-s "$dir/$_");
}

print $totalsize,$/;

Shawn

-----Original Message-----
From: danield [mailto:[EMAIL PROTECTED] 
Sent: Sunday, December 28, 2003 12:15 AM
To: perl_beginer
Subject: How to count the size of files in a directory


Hello all,

I do have a beautiful script, that counts a size of specified files
("ABAA.txt", "ABAC.txt") in a directory test. I have got this script from
discussion board. 

Here is the script:

my $dir='c:\\test';
my @files2check = ("ABAA.txt", "ABAC.txt");

my $totalSize= 0;
foreach (@files2check) {
   $totalSize += (-s "$dir\\$_");
}

print $totalSize;

I would like to modify it that it will count the size of all files in the
directory, EXCEPT those in list or so it will count the size of files that
match first 2 characters "AB" (sort of AB*) Can anybody advice?

Thank you for your time.

danield



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to