finding out if a directory is empty in C program
Chris Davies
chris at visionware.co.uk
Sat May 4 01:58:17 AEST 1991
>In article <1991Apr25.022029.5476 at csc.canberra.edu.au>, rvp at softserver.canberra.edu.au (Rey Paulo) writes:
>|> Is there any system call or library routine in UNIX which tests whether
>|> a directory is empty?
In article <1991Apr25.223540.19303 at athena.mit.edu> jik at athena.mit.edu (Jonathan I. Kamens) writes:
>No. You open the directory with opendir() and read it, and if the only
>entries in it are "." and "..", it's empty. Just like in a shell script
>(except the script uses ls, or shell wildcard expansion, instead of opendir()).
Why couldn't you use stat() and check whether the number of links == 2 ?
Most of the time it's not possible (well, not recommended) for _users_ to
hard-link to a directory, so the link-count wouldn't be wrong.
Chris
--
VISIONWARE LTD, 57 Cardigan Lane, LEEDS LS4 2LE, England
Tel +44 532 788858. Fax +44 532 304676. Email chris at visionware.co.uk
-------------- "VisionWare: The home of DOS/UNIX/X integration" -------------
More information about the Comp.unix.questions
mailing list