in reply to checking to see if a directory is empty

Rather than iterating you could use stat to look at the nlink field; on a *NIX system an empty directory should have exactly two links (one from its parent to itself, and one from its own . entry).

--
We're looking for people in ATL

Replies are listed 'Best First'.
Re^2: checking to see if a directory is empty
by mhi (Friar) on Nov 17, 2006 at 13:14 UTC
    Note that some *NIX flavors do allow hard links to directories! It is admittedly highly unlikely that your friendly sysadmin would dare to use this privilege, for fear of corrupting the file system.

    However, if she did, that directory would have a higher linkcount than expected, even when devoid of subdirectories.

    Also note that files contained in a directory do not count towards the directory's link-count. Only immediate subdirectories do.