Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: checking to see if a directory is empty

by cmeyer (Pilgrim)
on Jul 27, 2005 at 18:27 UTC ( [id://478695]=note: print w/replies, xml ) Need Help??


in reply to checking to see if a directory is empty

How about using opendir() and readdir()?

my $dir = '/tmp/foo'; if ( my @contents = dir_contents( $dir ) { do_something_about_it( $dir, @contents ); } else { it_is_empty( $dir ) } sub dir_contents { my $dir = shift; opendir DIR, $dir or die "Couldn't open $dir: $!"; return grep !/^\.\.?$/, readdir DIR; }

-Colin.

WHITEPAGES.COM | INC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://478695]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-19 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found