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

Richard O'Keefe ok@REDACTED
Tue Mar 13 22:59:37 CET 2012

On 14/03/2012, at 5:01 AM, Taavi Talvik wrote:

> On Mar 13, 2012, at 5:18 PM, Wes James wrote:
>> On Tue, Mar 13, 2012 at 12:09 AM, Zabrane Mickael <zabrane3@REDACTED> 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.
> On unix systems link_count=2 means, that directory is empty:

No it doesn't.  It means that the directory has no *subdirectories*.

f% mkdir fred
f% ls -l fred
total 0
f% ls -ld fred
drwxr-xr-x   2 me       cstaff       512 Mar 14 10:56 fred
f% touch fred/jim
f% ls -ld fred
drwxr-xr-x   2 me       cstaff       512 Mar 14 10:58 fred
f% mkdir fred/harry
f% ls -ld fred
drwxr-xr-x   3 me       cstaff       512 Mar 14 10:59 fred

More information about the erlang-questions mailing list