[EMAIL PROTECTED] wrote:
> Hi,
>
> I want to determine if a directory is empty and delete it.
> I have tried
> if ( -d $dd && -z $dd)
> but that doesn't seem to work. Does -z work
> only with plain files?
>
> Should I read the directory and if it contains only . and .., determine
> that
> is empty? It must be an easier way than that. Any ideas?
You can't expect to do everything with one line of code.
One way - untested:
sub is_empty {
my $dir = shift;
opendir DIR, $dir or die "opendir $dir: $!";
my @files = readdir DIR;
closedir DIR;
return 1 if @files == 2;
return 0;
}
__END__
--
,-/- __ _ _ $Bill Luebkert ICQ=162126130
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs