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

Zabrane Mickael zabrane3@REDACTED
Wed Mar 14 09:07:59 CET 2012


Yes and no.

When testing Taavi's solution on OSX, the "link_count" takes into account both files and subdirs.
But on Linux, it only counts subdirs.

Regards,
Zabrane

On Mar 13, 2012, at 11:26 PM, Taavi Talvik wrote:

> 
> On Mar 13, 2012, at 11:59 PM, Richard O'Keefe wrote:
>>> On unix systems link_count=2 means, that directory is empty:
>> 
>> No it doesn't.  It means that the directory has no *subdirectories*.
> 
> Mental note to myself - verify before posting;) 
> Sorry for confusion!
> 
> Yes - thats correct. Link count > 2 means, that there are subdirectories.
> (On unix, mac os x behaves differently). 
> 
> Richard's opendir/readir C code is only reasonably portable way. 
> Similar implementation for windows with _findfirst/_findnext is at
> http://www.two-sdg.demon.co.uk/curbralan/code/dirent/dirent.html
> 
> C-code and port/NIF are way to go.
> 
> best regards,
> taavi
> --
> "We should forget about small efficiencies, about 97 percent of the time. 
> Premature optimization is the root of all evil." Donald Knuth
> 
> Taavi Talvik
> taavi@REDACTED
> +372 5656 9996
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions





More information about the erlang-questions mailing list