Ignore:
Timestamp:
Oct 12, 2010, 4:15:37 PM (9 years ago)
Author:
rme
Message:

New functions DELETE-EMPTY-DIRECTORY and DELETE-DIRECTORY.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lib/pathnames.lisp

    r14334 r14358  
    156156                                             :defaults dest-path)))
    157157              (copy-file f dest-file :if-exists :supersede :preserve-attributes t)))))))
     158
     159(defun delete-empty-directory (path)
     160  (let* ((namestring (native-translated-namestring path))
     161         (err (%rmdir namestring)))
     162    (or (eql 0 err) (signal-file-error err path))))
     163
     164(defun delete-directory (path)
     165  "Delete specified directory and all its contents."
     166  (let ((namestring (native-translated-namestring path)))
     167    (if (eq :directory (%unix-file-kind namestring t))
     168      (let* ((dir (ensure-directory-pathname path))
     169             (wild (make-pathname :name :wild :type :wild :defaults dir))
     170             (files (directory wild :directories nil :files t
     171                               :follow-links nil :include-emacs-lockfiles t))
     172             (subdirs (directory wild :directories t :files nil
     173                                 :follow-links nil
     174                                 :include-emacs-lockfiles t)))
     175        (dolist (f files)
     176          (delete-file f))
     177        (dolist (d subdirs)
     178          (delete-directory d))
     179        (delete-empty-directory path))
     180      (error "~s is not a directory" path))))
    158181
    159182;;; use with caution!
Note: See TracChangeset for help on using the changeset viewer.