CAB Posted January 6, 2010 Posted January 6, 2010 CAB: A bit of overkill? When you go hunting you must use a grenade launcher to zap a squirrel! LOL No but I use a BIG gun:twisted: Quote
todouble22 Posted January 6, 2010 Author Posted January 6, 2010 A bit of an overkill perhaps but this is mine. ;; del_files.lsp ;; CAB 10/09/2006 ;; Version 2.0 12.16.2009 added file report & replace folder dialog ;; ;; User selects top folder, allows subfolders, enters file types ;; File types matching are then deleted. ;; ;; (defun c:del_files (/ CNT CNTFAILED F OutFile FNAME FNAMELST FOLDER FTYPE FTYPES FULLPATH PATH PLISTS usesub X get_subs *error* ) ;;=============================================== ;; L o c a l F u n c t i o n s ;;=============================================== ;; error function & Routine Exit ;| (defun *error* (msg) (if (not (member msg '("console break" "Function cancelled" "quit / exit abort" "") ) ) (princ (strcat "\nError: " msg)) ) ; endif (if fso (vlax-release-object fso) ) (gc) (princ) ) |; ;; Return all directories (defun get_subs (folder / file) (mapcar '(lambda (x) (setq file (strcat folder "\\" x)) (cons file (apply 'append (get_subs file))) ) (cddr (vl-directory-files folder nil -1)) ) ) ;; FolderBox (Patrick_35) (defun FolderBox (message directory flag / folder sh) ;; Arguments: ;; message: the message displayed in th dialog box ;; directory: the directory to browse ;; flag values: ;; 0 = Default ;; 1 = Only file system folders can be selected. If this bit is set, the OK button is disabled if the user selects a folder that doesn't belong to the file system (such as the Control Panel folder). ;; 2 = The user is prohibited from browsing below the domain within a network (during a computer search). ;; 4 = Room for status text is provided under the text box. ;; 8 = Returns file system ancestors only. ;; 16 = Shows an edit box in the dialog box for the user to type the name of an item. ;; 32 = Validate the name typed in the edit box. ;; 512 = None "New folder" button ;; 4096 = Enables the user to browse the network branch of the shell's namespace for computer names. ;; 8192 = Enables the user to browse the network branch of the shell's namespace for printer names. ;; 16384 = Allows browsing for everything. (setq shell (vlax-create-object "Shell.Application")) (if (setq folder (vlax-invoke shell 'browseforfolder 0 message flag directory) ) (setq folder (vlax-get-property (vlax-get-property folder 'self) 'path)) (setq folder nil) ) (vlax-release-object shell) folder ) ;;=========================================================== ;; M a i n P r o g r a m ;;=========================================================== (setq path "" ; use current path ftypes "" ; show all types ) ;;Old method (setq fullpath (getfiled "Select a File in the top folder." path ftypes 4) ) (setq fullpath (FolderBox "Select top folder for File Delete:" (vl-filename-directory(findfile "acad.exe")) 0)) (if (and fullpath ;;Old method (setq path (vl-filename-directory fullpath)) ; extract path (setq path fullpath) ; new method ;;(setq fname (vl-filename-base fullpath)) ; extract name only ;;(setq ftype (vl-filename-extension fullpath)) ; extract file type ) (progn (initget "Yes No") (setq usesub (getkword "\nSearch in Subdirectories? [Yes/No] <No>")) (or usesub (setq usesub "No")) (initget "All bak bk1 bk2 sv$ ac$ log plt Ls Dc dS") (setq ftype (getkword "\nEnter File type [All bak bk1 bk2 sv$ ac$ log plt Ls Dc dS] <bak>")) (or ftype (setq ftype "bak")) (cond ((member ftype '("Ls" "Dc")) ; correct for missing _ character (setq ftype (list (strcat "_" ftype))) ) ((= ftype "All")(setq ftype '("bak" "bk1" "bk2" "sv$" "ac$" "log" "plt" "_Ls" "_Dc" "dS"))) (t (setq ftype (list ftype))) ) (prompt "\n *** Working - Please wait ***\n") (if (= usesub "Yes") (setq plists (cons (list path) (get_subs path))) ; use all subfolders too (setq plists (list path)) ; only current path ) (setq cnt 0 cntfailed 0 ) (if (setq OutFile (open (strcat path "\\FileDelList.txt") "w")) (progn (write-line (strcat (substr (rtos (getvar "CDATE") 2 4) 5 2) ; month "-" (substr (rtos (getvar "CDATE") 2 4) 7 2) ; day "-" (substr (rtos (getvar "CDATE") 2 4) 1 4) ; year "2007" ) OutFile) (write-line "=================================================" OutFile) (foreach pl plists (if (not (listp pl)) (setq pl (list pl))) (foreach pa pl (foreach ft ftype ;; get A LIST OF matching FILE NAMES (setq fnamelst (vl-directory-files pa (strcat "*." ft) 1)) (if fnamelst (foreach fn fnamelst (if (vl-file-delete (strcat pa "\\" fn)) (progn (write-line (strcat pa "\\" fn) OutFile) (setq cnt (1+ cnt)) ) (setq cntfailed (1+ cntfailed)) ) ) ) ) ) ) (write-line "=================================================" OutFile) (write-line (strcat (itoa cnt) " files were deleted.") OutFile) (write-line (strcat (itoa cntfailed) " files could NOT be deleted.") OutFile) (close OutFile) ; close the open file handle ) ) (if (not (zerop cnt)) (prompt (strcat "\nReport File --> " path "\\FileDelList.txt \n" (itoa cnt) " files were deleted."))) (if (not (zerop cntfailed)) (prompt (strcat "\n" (itoa cntfailed) " files could NOT be deleted.")) ) (if (and (zerop cnt) (zerop cntfailed)) (prompt (strcat "\n*** No matching files found ***.")) ) ) (prompt "\nUser Quit.") ) (princ) ) with this code I need to (vl-load-com) for it to work. Is there a reason that its not loaded every time I open autocad? and the only problem with it is that the file search dialogue box that comes up doesnt get to the folder structure that I need to access Quote
Lee Mac Posted January 6, 2010 Posted January 6, 2010 with this code I need to (vl-load-com) for it to work. Is there a reason that its not loaded every time I open autocad? Most people (including me!) put a call to (vl-load-com) in their ACADDOC.lsp, so don't notice when it is missing... Quote
CAB Posted January 6, 2010 Posted January 6, 2010 vl-load-com What Lee said. Change this line to adjust the TOP folder. (setq fullpath (FolderBox "Select top folder for File Delete:" (vl-filename-directory(findfile "acad.exe")) 0)) Quote
todouble22 Posted January 6, 2010 Author Posted January 6, 2010 Most people (including me!) put a call to (vl-load-com) in their ACADDOC.lsp, so don't notice when it is missing... do I just type load (vl-load-com) into it? Or is there a special way to add it into the ACADDOC.lsp? Quote
Lee Mac Posted January 6, 2010 Posted January 6, 2010 Just put (vl-load-com) anywhere in the ACADDOC.lsp Quote
todouble22 Posted January 6, 2010 Author Posted January 6, 2010 vl-load-com What Lee said. Change this line to adjust the TOP folder. (setq fullpath (FolderBox "Select top folder for File Delete:" (vl-filename-directory(findfile "acad.exe")) 0)) Thank you, I'm learning as I go with coding so bare with me here but what do I go about changing for it to search through like my local user c:drive for example? Quote
Lee Mac Posted January 6, 2010 Posted January 6, 2010 Perhaps: (setq fullpath (FolderBox "Select top folder for File Delete:" nil 0)) Quote
Lee Mac Posted January 6, 2010 Posted January 6, 2010 Not sure if it will help, but the BrowseForFolder method that the "FolderBox" function uses is described here. Lee Quote
todouble22 Posted January 6, 2010 Author Posted January 6, 2010 Not sure if it will help, but the BrowseForFolder method that the "FolderBox" function uses is described here. Lee thanks cab and leeMac always appreciated Quote
Lee Mac Posted January 6, 2010 Posted January 6, 2010 thanks cab and leeMac always appreciated You're welcome Todd Quote
StevJ Posted January 6, 2010 Posted January 6, 2010 Or you could make a batch file with the contents: del C:\TEST\"Working Drawings"\*.bak >NUL Then toss it on your desktop and run it whenever you want. Steve Quote
todouble22 Posted January 6, 2010 Author Posted January 6, 2010 Or you could make a batch file with the contents: del C:\TEST\"Working Drawings"\*.bak >NUL Then toss it on your desktop and run it whenever you want. Steve thanx steve that is what i have done in the past just checkin on other users' tricks Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.