Common Lisp 刪除指定路徑下的空目錄

X3J13移除了一些對路徑的操做函數,只保留pathname和directory相關的基本函數,cl-fad實現了路徑操做的多數接口。bash

CL-USER> (ql:quickload "cl-fad")
To load "cl-fad":
  Load 1 ASDF system:
    cl-fad
; Loading "cl-fad"

("cl-fad")
CL-USER> (defun delete-empty-directory (filepath)
	   (cl-fad:walk-directory filepath (lambda (file) 
					     (if (and 
						  (cl-fad:directory-pathname-p file) 
						  (null (cl-fad:list-directory file))) 
						 (progn 
						   (format t "delete ~a~%~%" file)
						   (cl-fad:delete-directory-and-files file)))) 
				  :directories t))
DELETE-EMPTY-DIRECTORY
CL-USER>

在「d:/迅雷下載」目錄下新建aaaa空目錄,而後執行一下語句:函數

CL-USER> (delete-empty-directory "d:/迅雷下載")
delete d:/迅雷下載/aaaaaa/
相關文章
相關標籤/搜索