Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-12-28 09:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (179 votes), past polls