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

Re: Quickly checking if a directory is empty

by alexm (Chaplain)
on Aug 18, 2009 at 20:55 UTC ( #789592=note: print w/ replies, xml ) Need Help??

in reply to Quickly checking if a directory is empty

Using File::Slurp::read_dir() as in:

use File::Slurp; if ( read_dir('/path/to/dir') == 0 ) { print "is empty!\n"; }

Update: using File::Slurp or Path::Class will have bad performance on a directory with a large number of entries. However, File::Find::Rule::DirectoryEmpty is addressing the problem the right way, as mentioned by Fletch, by looking for any other entry aside from "." and ".." (which means 3 readdir calls at most whatever the number of entries).

Comment on Re: Quickly checking if a directory is empty
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2015-11-25 01:31 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (667 votes), past polls