Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uupsi!decvax!prcrs!paul From: paul@prcrs.prc.com (Paul Hite) Newsgroups: comp.unix.questions Subject: Re: How do I tell when a directory is empty in a script? Message-ID: <1798@prcrs.prc.com> Date: 4 Apr 91 16:51:07 GMT References: <1991Mar30.040400.13893@ncsu.edu> <1991Apr3.142150.4445@athena.mit.edu> Organization: PRC Realty Systems, McLean, VA Lines: 33 In article <1991Apr3.142150.4445@athena.mit.edu>, jik@athena.mit.edu (Jonathan I. Kamens) writes: > In article <1991Mar30.225406.20493@dg-rtp.dg.com>, hunt@dg-rtp.rtp.dg.com (Greg Hunt) writes: > |> Telling whether a directory is empty from a script should be possible > |> by looking at the size of the directory itself. If the directory size > |> is zero, then the directory is empty. Otherwise, it contains some > |> files. You should check this out on your system to make sure it holds > |> true for the flavor of UNIX that you're using. > > Um, I can't imagine this being true for *any* remotely normal flavor of Unix. > Well Jonathan, HP's old 9000/500 series did behave that way and it was *remotely* normal. The 500 used a screwy filesystem which HP called SDF (Structured Directory Format). SDF was somewhat like the old Sys V filesystem. But the inode was larger and contained some extra fields. It had a creation date and parent directory among other things. The parent directory field was used only if the inode was for a directory. Newly created directories were indeed totally empty. The kernel handled "." and ".." specially. If you used opendir(3) and friends, you would see a "." and "..". Also ls would report them. But if you opened the directory and started reading and expected to find a . and .. entries, you would lose. The creation date was largely useless. The kernel would put the date in the inode, but there was no way access it via any system call. It was accessible via the raw device of course. And HP did have a custom fsdb that could display and modify it. HP's current incarnation of HP-UX still has some limited support for SDF. Paul Hite PRC Realty Systems McLean,Va uunet!prcrs!paul (703) 556-2243 You can't tell which way the train went by studying its tracks.