Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!uunet!mcsun!ukc!vision!chris From: chris@visionware.co.uk (Chris Davies) Newsgroups: comp.unix.questions Subject: Re: finding out if a directory is empty in C program Message-ID: <1991May3.155817.1807@visionware.co.uk> Date: 3 May 91 15:58:17 GMT References: <900@homer.UUCP> <1991Apr15.180550.14750@beaver.cs.washington.edu> <1991Apr18.054735.6733@metapro.DIALix.oz.au> <1991Apr25.022029.5476@csc.canberra.edu.au> <1991Apr25.223540.19303@athena.mit.edu> Reply-To: chris@visionware.co.uk (Chris Davies) Organization: VisionWare Ltd., Leeds, UK Lines: 18 >In article <1991Apr25.022029.5476@csc.canberra.edu.au>, rvp@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@athena.mit.edu> jik@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@visionware.co.uk -------------- "VisionWare: The home of DOS/UNIX/X integration" -------------