歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> newLISP 遍歷目錄樹,清理編譯目錄

newLISP 遍歷目錄樹,清理編譯目錄

日期:2017/3/1 9:53:57   编辑:Linux編程

下面的代碼將當前目錄下所有子目錄裡面的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

Copyright © Linux教程網 All Rights Reserved