Results 1 to 6 of 6

Thread: Selecting a list of folders and removing all ".bak", ".err", ".xlg" & "plot.log" files from folders & sub folders

  1. #1
    I could stop if I wanted to
    Join Date
    2005-08
    Posts
    378
    Login to Give a bone
    0

    Cool Selecting a list of folders and removing all ".bak", ".err", ".xlg" & "plot.log" files from folders & sub folders

    Guys,
    Is it possible to be able to select multiple folders in a drive and have all ".bak", ".err", ".xlg" & "plot.log" files removed from not only those files but also any sub folders using lisp ?
    Does anyone have anything like this they would share ?

    Stephen

  2. #2
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    202
    Login to Give a bone
    0

    Default Re: Selecting a list of folders and removing all ".bak", ".err", ".xlg" & "plot.log" files from folders & sub folders

    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)
    )
    Last edited by 'gile'; 2007-10-12 at 09:54 AM.

  3. #3
    Member
    Join Date
    2007-05
    Posts
    7
    Login to Give a bone
    0

    Default Re: Selecting a list of folders and removing all ".bak", ".err", ".xlg" & "plot.log" files from folders & sub folders

    I run the following batch file nightly using scheduler to delete unwanted files prior to our scheduled tape backup.

    del F:\*.gid /s /q /f
    del F:\*.bak /s /q /f
    del F:\*.dmp /s /q /f
    del F:\*.bp3 /s /q /f
    del F:\*.sv$ /s /q /f
    del F:\*.err /s /q /f
    del F:\*.bk1 /s /q /f

  4. #4
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    202
    Login to Give a bone
    0

    Default Re: Selecting a list of folders and removing all ".bak", ".err", ".xlg" & "plot.log" files from folders & sub folders

    Here's a more convivial version, using dialog boxes
    (comments aren't translated)

    Code:
    ;;; GetFolders
    ;;; Retourne la liste de tous les sous-dossiers du dossier (ou disque) spécifié (chemin)
    
    (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
    ;; Transforme un chaine avec séparateur en liste de chaines
    ;;
    ;; Arguments
    ;; str : la chaine à transformer en liste
    ;; sep : le séparateur
    ;;
    ;; Exemples
    ;; (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)
      )
    )
    
    ;;; InputBox Ouvre une boite de dialogue pour récupérer une valeur (string)
    
    (defun InputBox	(Titre Message Defaut / *acad* users1 valeur)
      (setq	*acad* (vlax-get-acad-object)
    	users1 (getvar "users1")
      )
      (acad-push-dbmod)
      (vla-eval *acad*
    	    (strcat "ThisDrawing.SetVariable \"USERS1\","
    		    "InputBox (\""	   Message
    		    "\", \""		   Titre
    		    "\", \""		   Defaut
    		    "\")"
    		   )
      )
      (setq valeur (getvar "users1"))
      (setvar "users1" users1)
      (acad-pop-dbmod)
      valeur
    )
    
    ;;; MsgBox  -Patrick_35-
    ;;; Ouvre une boite de dialogue pour récupérer la réponse à une question
    
    (defun MsgBox (Titre Boutons Message Time / Reponse WshShell)
      (setq WshShell (vlax-create-object "WScript.Shell"))
      (setq	Reponse	(vlax-invoke
    		  WshShell
    		  'Popup
    		  Message
    		  Time
    		  Titre
    		  (itoa Boutons)
    		)
      )
      (vlax-release-object WshShell)
      Reponse
    )
    
    ;;; DirBox -Patrick_35-
    
    (defun DirBox (Message Chemin Drapeau / rep sh)
      (vl-load-com)
      (setq sh (vlax-create-object "Shell.Application"))
      (if (setq
    	rep (vlax-invoke sh 'browseforfolder 0 Message Drapeau Chemin)
          )
        (setq rep (vlax-get-property (vlax-get-property rep 'self) 'path))
        (setq rep nil)
      )
      (vlax-release-object sh)
      rep
    )
    
    ;; CleanFolder (gile)
    ;; Supprime du dossier et de ses sous dossier tous les fichiers
    ;; aux formats spécifiées (séparateur = virgule).
    
    (defun c:cleanfolder (/ path exts cnt)
      (vl-load-com)
      (and
        (setq path (dirbox "Select the folder" "" 512))
        (/=	""
    	(setq exts
    	       (inputbox
    		 "Cleanfolder"
    		 "Enter the extensions of the files to be deleted
    	     \n(separator = comma)"
    		 ""
    	       )
    	)
        )
        (= 6
           (msgbox
    	 "CleanFolder"
    	 52
    	 (strcat "Do you realy want to delete all the files\n"
    		 exts
    		 "\nfrom the folder\n"
    		 path
    	 )
    	 10
           )
        )
        (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	"*."
    				(vl-string-left-trim
    				  "."
    				  (vl-string-left-trim "*" ext)
    				)
    			)
    		      )
    	      )
    	    )
    	   (str2lst exts ",")
    	 )
           )
          (cons path (getfolders path))
        )
        (alert (strcat (itoa cnt) " deleted files"))
      )
      (princ)
    )

  5. #5
    I could stop if I wanted to
    Join Date
    2001-10
    Location
    Defragging the internets.
    Posts
    350
    Login to Give a bone
    0

    Default Re: Selecting a list of folders and removing all ".bak", ".err", ".xlg" & "plot.log" files from folders & sub folders

    Quote Originally Posted by bob.vandusen View Post
    I run the following batch file nightly using scheduler to delete unwanted files prior to our scheduled tape backup.

    del F:\*.gid /s /q /f
    del F:\*.bak /s /q /f
    del F:\*.dmp /s /q /f
    del F:\*.bp3 /s /q /f
    del F:\*.sv$ /s /q /f
    del F:\*.err /s /q /f
    del F:\*.bk1 /s /q /f
    Thanks for the batch routine. I had one for creating a text file to show our *plt files.

    If you want a list you can change it to:
    Dir F:\*.gid *.bak *.dmp *.bp3 *.sv$ *.err *.bk1 /s /q > F_Drive_Junk.txt

    Chris

  6. #6
    Woo! Hoo! my 1st post
    Join Date
    2009-04
    Posts
    1
    Login to Give a bone
    0

    Default Re: Selecting a list of folders and removing all ".bak", ".err", ".xlg" & "plot.log" files from folders & sub folders

    hello everybody!

Similar Threads

  1. Replies: 0
    Last Post: 2012-06-06, 11:54 AM
  2. ENTIDADES EN ALIGNMENT COMO "FIXED", "FLOTING" y "FREE"
    By cadia in forum AutoCAD Civil 3D - General
    Replies: 1
    Last Post: 2009-02-01, 04:21 AM
  3. Replies: 3
    Last Post: 2007-10-23, 09:06 PM
  4. Replies: 8
    Last Post: 2007-04-04, 12:39 PM
  5. Replies: 1
    Last Post: 2006-06-13, 06:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •