Danield wrote: > > 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?
Hi. There are two main choices here: 'readdir' or 'glob'. Once you have retrieved the list of file names in the directory you need to filter out those that aren't plain files (i.e. folders on Windows) and those that are in your list of exclusions. The program below should do the trick. To make it accumulate the sizes of files beginning with 'AB' change the line next if grep $_ eq $name, @files2check; to next unless $name =~ /^AB/; (You could do it in the 'glob' call, but this approach makes it more general.) HTH, Rob use strict; use warnings; my $dir = 'C:\test'; my @files2check = ('ABAA.txt', 'ABAC.txt'); my $totalSize = 0; foreach my $name (glob "$dir\\*") { my $file = "$dir\\$name"; next unless -f $file; next if grep $_ eq $name, @files2check; $totalSize += (-s $file); } print $totalSize; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>