Here's one I wrote to delete certain types of files in folders.
You can modify it if you don't need to do all that.
(defun *list_folders* (path sub)
(defun get_folders (folder / f)
(mapcar '(lambda (x)
(setq f (strcat folder "\\" x))
(if sub
(cons f (apply 'append (get_folders f)))
)
)
(cddr (vl-directory-files folder nil -1))
)
)
(cons path (apply 'append (get_folders path)))
)
(defun get_files (path exts)
(apply 'append
(mapcar '(lambda (x)
(mapcar '(lambda (y)
(mapcar '(lambda (z) (strcat x "\\" z))
(vl-directory-files x y 1)
)
)
exts
)
)
path
)
)
)
;;;usage
;;;(c:all_files T) T=search sub folders nil=don't search subfolders
(defun c:all_files (sub_folders / lst exts)
(setq exts '("*.bak" "*.bk*" "*.$$$" "*.ac$"))
(setq lst
(apply 'append
(get_files
(*list_folders*
(acet-ui-pickdir
(strcat "Searches for all files that match this "
"criteria: *.bak, *.bk*, *.$$$, and *.ac$"
)
"Y:\\Common\\Projects"
"Select a Folder"
)
sub_folders
)
exts
)
)
)
(mapcar 'vl-file-delete lst)
(princ)
)
WARNING:
If code posted above is run as is, it will delete files. Do not test fully unless you understand the code.