newLISP 遍历目录树,清理编译目录

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/b548e35880ed9932c54df2b2c65f24e2.html