[erlang-questions] Best way to check if a given directory is empty (or not)?
Attila Rajmund Nohl
Tue Mar 13 10:58:46 CET 2012
2012/3/13 Zabrane Mickael <>:
> 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
> The problem with them is they both return a list of filenames.
> I'd like to avoid getting this list back to be able to check if it's empty or not.
> Advices please?
Maybe call opendir, then readdir once (through NIFs). If it returns
NULL, the directory is empty. I'm not sure about the portability,
> erlang-questions mailing list
More information about the erlang-questions