How do I tell when a directory is empty in a script?

Paul Hite paul at prcrs.prc.com
Fri Apr 5 02:51:07 AEST 1991


In article <1991Apr3.142150.4445 at athena.mit.edu>, jik at athena.mit.edu (Jonathan I. Kamens) writes:
> In article <1991Mar30.225406.20493 at dg-rtp.dg.com>, hunt at 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.



More information about the Comp.unix.questions mailing list