[erlang-questions] Best way to check if a given directory is empty (or not)?

Richard O'Keefe <>
Tue Mar 13 08:12:30 CET 2012


On 13/03/2012, at 7:09 PM, Zabrane Mickael wrote:

> Hi guys,
> 
> I'd like to know if there's a good and portable method to check if a directory is empty (or not)?
> In my case, the directory can contains huge number (more than 150K in average) of files if it is not empty.
> 
> I've tested the following working calls:
> a. file:list_dir/1
> b. filelib:wildcard/2

I don't know about filelib, but file:list_dir/1 used to work by going through several
layers and finally sending a command to the 'efile' driver.  You might have to extend
the driver.

For POSIX systems you could always run an outboard command.  The Windows 'SUA' kit should
be POSIX enough for this to work.




More information about the erlang-questions mailing list