下面的代码将当前目录下所有子目录里面的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返回的虽然是当前目录的子文件,但是只有文件名,路径还要自己拼接。我就在这个地方没有注意,卡了一小时。