changeset 105347:667ddf91d885

* files.el (delete-directory): New defun. The original function in fileio.c has been renamed to `delete-directory-internal'.
author Michael Albinus <michael.albinus@gmx.de>
date Thu, 01 Oct 2009 15:04:22 +0000
parents 57afd13b64b9
children 1aa50e5c7523
files lisp/files.el
diffstat 1 files changed, 32 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/files.el	Thu Oct 01 15:01:32 2009 +0000
+++ b/lisp/files.el	Thu Oct 01 15:04:22 2009 +0000
@@ -4631,6 +4631,38 @@
 	  (while create-list
 	    (make-directory-internal (car create-list))
 	    (setq create-list (cdr create-list))))))))
+
+(defun delete-directory (directory &optional recursive)
+  "Delete the directory named DIRECTORY.  Does not follow symlinks.
+If RECURSIVE is non-nil, all files in DIRECTORY are deleted as well."
+  (interactive
+   (let ((dir (expand-file-name
+	       (read-file-name
+		"Delete directory: "
+		default-directory default-directory nil nil))))
+     (list dir
+	   (if (directory-files
+		dir nil "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")
+	       (y-or-n-p
+		(format "Directory `%s' is not empty, really delete? " dir))
+	     nil))))
+  ;; If default-directory is a remote directory,
+  ;; make sure we find its delete-directory handler.
+  (setq directory (directory-file-name (expand-file-name directory)))
+  (let ((handler (find-file-name-handler directory 'delete-directory)))
+    (if handler
+	(funcall handler 'delete-directory directory recursive)
+      (if (and recursive (not (file-symlink-p directory)))
+	  (mapc
+	   (lambda (file)
+	     (if (file-directory-p file)
+		 (delete-directory file recursive)
+	       (delete-file file)))
+	   ;; We do not want to delete "." and "..".
+	   (directory-files
+	    directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
+      (delete-directory-internal directory))))
+
 
 (put 'revert-buffer-function 'permanent-local t)
 (defvar revert-buffer-function nil