PerlPlay has asked for the wisdom of the Perl Monks concerning the following question:
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?
#!/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++; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can File:Find be used to find empty dirs?
by Kenosis (Priest) on Nov 20, 2013 at 06:21 UTC | |
by PerlPlay (Novice) on Nov 20, 2013 at 13:29 UTC | |
by Kenosis (Priest) on Nov 20, 2013 at 20:32 UTC | |
|
Re: Can File:Find be used to find empty dirs?
by dasgar (Priest) on Nov 20, 2013 at 06:01 UTC | |
|
Re: Can File:Find be used to find empty dirs?
by 2teez (Vicar) on Nov 20, 2013 at 09:03 UTC | |
by PerlPlay (Novice) on Nov 20, 2013 at 22:40 UTC | |
by 2teez (Vicar) on Nov 21, 2013 at 11:48 UTC | |
by PerlPlay (Novice) on Nov 20, 2013 at 13:26 UTC |