下面的代碼將當前目錄下所有子目錄裡面的dll, pdb, obj和lib文件全部刪除。
文件名clean.lsp
;; remove *.lib, *.dll, *.pdb and *.obj in current folder
;; then handle sub folders
(define (clean-folder dir-path)
(println "enter " dir-path)
(let (fs (directory dir-path "\\.dll|\\.pdb|\\.obj|\\.lib"))
(dolist (af fs)
(begin
(println (append "remove file: " af))
(delete-file (append dir-path "\\" af))
)
))
(let (files (directory dir-path {^[a-z]}))
(begin
(dolist (f files)
(let (cf (append dir-path "\\" f))
(if (directory? cf)
(clean-folder cf))))
)))
(clean-folder (real-path) )
(exit)
主要當心函數directory返回的雖然是當前目錄的子文件,但是只有文件名,路徑還要自己拼接。我就在這個地方沒有注意,卡了一小時。
相關閱讀: 為Emacs配置newLISP開發環境 http://www.linuxidc.com/Linux/2013-01/78463.htm