in reply to Re: How to tell if a Directory is Empty
in thread How to tell if a Directory is Empty

I was trying to be clever, so I discovered IO::Dir and seekdir

I wrote this code, and then had a WTF moment

sub dirEmpty { my $d = IO::Dir->new( @_ ); return defined( $d && $d->seek( 2 ) && scalar $d->read ); }

seekdir is broken on my win32 machine :)

Replies are listed 'Best First'.
Re^3: How to tell if a Directory is Empty
by Anonymous Monk on Nov 27, 2011 at 10:05 UTC

        glob, unlike readdir, does not look for "hidden" files unless you explicitly include them in the pattern. And if you do so, you'll find also the standard directory entries . and ..:

        /home>cd /tmp/ /tmp>mkdir foo /tmp>cd foo /tmp/foo>touch .hidden /tmp/foo>perl -E 'die "oops" unless !!<*>' oops at -e line 1. /tmp/foo>perl -E 'say for <*>' /tmp/foo> /tmp/foo>perl -E 'say for <.*>' . .. .hidden /tmp/foo>

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)