use strict;
use warnings;
my $testfolder = './test';
my @newfiles;
if ( opendir(my $dir, $testfolder) ) {
while ( my $file = readdir($dir) ) {
# skip parent and current directories
next if ($file eq '.' || $file eq '..');
# skip directories
next if (-d $file);
# create the fullpath
my $full_pathname = $testfolder . "/" . $file;
next unless (-e $full_pathname);
# get the filesize
my $filesize = -s $full_pathname;
# push the non-zero sized file to the new file array
if ($filesize) {
push(@newfiles,$file);
}
}
closedir($dir);
} else {
die "[Error] UNABLE TO OPEN DIRECTORY: [$!]";
}
foreach my $file (@newfiles) {
print "$file\n";
}
|