Search code examples
perlfilesizeglob

How do I output names of empty files in the current directory?


I’m trying to check my folder for files that are empty (0 bytes). I have about 1,200 files so Perl will make this task very easy :)

Here is my code so far but it doesn't seem to work. (It’s just listing all of the files.) Can anyone teach me what I’ve done wrong? Thanks!

#!/usr/bin/perl
@files = glob('*');
if ((-s @files) == 0) {
    print"@files\n";
}

Solution

  • #!/usr/bin/perl
    
    use strict; use warnings;
    
    foreach my $file (glob('*')) {
        unless (-s $file) {
            print "$file\n";
        }
    }