perlquestion
PerlPlay
<p>
I have the following code but it's telling me every directory is empty...
Is it possible to get this to actually work to find empty directories or do I have to use open dir etc?
<code>
#!/usr/bin/perl
# emptydir
# Checks for empty directories
# Ver 0.1 Nov 2013
use strict;
use warnings;
use File::Find;
my $drive = 'C:/Temp/';
my @empty;
my $ndirs = undef;
my $dsize = undef;
find(\&listing, $drive);
#Do stuff here
foreach my $files (@empty) {
print "Found empty folder $files\n";
}
print "Found $ndirs folders in total\n";
sub listing{
if (-d $File::Find::name) {
my $dsize = (stat($File::Find::name))[7];
if ($dsize == 0) {
push @empty, $File::Find::name;
}
$ndirs++;
}
}
</code>
</p>