[Openmcl-devel] delete-file and directories

Gary Byers gb at clozure.com
Sat Mar 12 00:34:56 PST 2005

On Thu, 10 Mar 2005, George Khouri wrote:

> Was there ever a discussion on this list as to whether delete-file
> should also remove a directory if a directory is passed to it as an
> arg, a la MCL? The only way I can find to remove a dir in OpenMCL is
> to make a call to #_rmdir.  The hyperspec is somewhat vague about
> delete-file: The "filespec" arg can be a pathname, and a directory
> can be a pathname, according to the definition of pathname.

I agree that there should be a simple, advertised way to delete a
directory, but I'm not sure that it should be DELETE-FILE.  (CL has
CREATE-FILE and ENSURE-DIRECTORIES-EXIST, so perhaps the missing
functionality should have been called something like

I also agree that the spec leaves a lot intentionally unsaid; it
says that DELETE-FILE deletes the -file- specified by its filespec
arg; the glossary entry for "file" says only that it's a named
entity that lives in the filesystem and whose nature is implementation-
dependent.  (So, it's not necessarily incorrect for an implementation
to interpret "file" to include "directories", and may be very reasonable
to do so in at least some hypothetical file systems.)

It's not clear that it's entirely reasonable to treat file deletion
and directory deletion identically on POSIX (or HFS, or Win32) file
systems; those systems generally only allow directories to be deleted
if they're empty, and "deleting an empty directory" and "recursively
deleting a directory and its contents" are generally somewhat different
operations.  So you might have something like:

(defun DELETE-DIRECTORY (pathname &optional (recursively nil))

e.g., it seems that it'd be desirable to maintain this distinction.
(There might be other plausible options: if some of the directory's
contents can't be deleted because of permission issues, how should
the function behave?  Etc.)

It's not clear how you'd wedge this into DELETE-FILE, which is defined
to take a single required argument.  (I can't cite chapter and verse
of the CLHS, but I don't think that there's any way for a conforming
implementation to extend the lambda list of a standard function in
cases like this.)

> What do other lisps do to delete a dir?

I'm not sure.  I did notice that a couple of implementations (including
MCL) extend DELETE-FILE to take &OPTIONAL or &KEY arguments, and that's
generally not a good thing (for other reasons). (In neither of these
cases did the extra argument have anything to do with directory

I could sort of believe that existing lisps -could- standardize on
some sort of de facto standard DELETE-DIRECTORY function, at least
partly because there are really only 2 or maybe 3 filesytems in
widespread use today and they all offer similar semantics.

> Thanks,
> George Khouri

More information about the Openmcl-devel mailing list