Hi,
This one doesn't allow to select multiple folders at once, but it clean up all the sub folders of the specified one.
Code:
;| GetFolders
;;; Returns the list of all sub folders of the specified folder or drive (path)
;;
;; Example
;; (GetFolders "C:\\Program Files\\AutoCAD 2007\\Help")
;; ("C:\\Program Files\\AutoCAD 2007\\Help\\buildyourworld"
"C:\\Program Files\\AutoCAD 2007\\Help\\Tutorials"
"C:\\Program Files\\AutoCAD 2007\\Help\\Tutorials\\createTransmittal"
"C:\\Program Files\\AutoCAD 2007\\Help\\Tutorials\\crossReference"
"C:\\Program Files\\AutoCAD 2007\\Help\\Tutorials\\crossReference\\Models"
"C:\\Program Files\\AutoCAD 2007\\Help\\Tutorials\\PlaceView"
"C:\\Program Files\\AutoCAD 2007\\Help\\Tutorials\\PlaceView\\Models"
"C:\\Program Files\\AutoCAD 2007\\Help\\Tutorials\\PublishSheetSet"
"C:\\Program Files\\AutoCAD 2007\\Help\\Tutorials\\sheetListTable"
"C:\\Program Files\\AutoCAD 2007\\Help\\Tutorials\\Symbol Libraries"
"C:\\Program Files\\AutoCAD 2007\\Help\\Tutorials\\ViewSheetSet"
"C:\\Program Files\\AutoCAD 2007\\Help\\Tutorials\\ViewSheetSet\\xrefs")
|;
(defun GetFolders (path / l c)
(if (setq l (vl-directory-files path nil -1))
(apply 'append
(mapcar '(lambda (x)
(cons (setq c (strcat path "\\" x)) (GetFolders c))
)
(vl-remove "." (vl-remove ".." l))
)
)
)
)
;; str2lst
;; Parses a string in a sub string list
;;
;; Arguments
;; str : the string to be parsed
;; sep : the separator
;;
;; Examples
;; (str2lst "a b c" " ") -> ("a" "b" "c")
;; (str2lst "1,2,3" ",") -> ("1" "2" "3")
;; (mapcar 'read (str2lst "1,2,3" ",")) -> (1 2 3)
(defun str2lst (str sep / pos)
(if (setq pos (vl-string-position (ascii sep) str))
(cons (substr str 1 pos)
(str2lst (substr str (+ (strlen sep) pos 1)) sep)
)
(list str)
)
)
;; CleanFolder
;; Deletes all files with specified extensions in the specified folder and sub folders
(defun c:cleanfolder (/ path exts cnt)
(and
(or
(/= ""
(setq
path (getstring T "\nEnter the folder path <Dialog box>: ")
)
)
(setq path
(vl-filename-directory
(getfiled "Select a file in the folder to be cleaned"
""
""
0
)
)
)
)
(setq exts (getstring "\nEnter the extensions (bak,err,log,...): "))
(setq cnt 0)
(mapcar
'(lambda (fold)
(mapcar '(lambda (ext)
(mapcar '(lambda (file)
(vl-file-delete
(strcat fold "\\" file)
)
(setq cnt (1+ cnt))
)
(vl-directory-files fold (strcat "*." ext))
)
)
(str2lst exts ",")
)
)
(cons path (getfolders path))
)
)
(princ (strcat "\n\t" (itoa cnt) " files deleted"))
(princ)
)