Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!agate!ucbvax!bloom-beacon!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.questions Subject: finding out if a directory is empty in C program (was Re: How do I tell when a directory is empty in a script?) Message-ID: <1991Apr25.223540.19303@athena.mit.edu> Date: 25 Apr 91 22:35:40 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> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Lines: 19 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? 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()). And if you have a system that doesn't have opendir() or something like it, instead forcing you to open and read the directory file directly, then you should find your vendor and shoot him. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710 Disclaimer: If you do find your vendor and shoot him, I'm not responsible. :-)