Jump to content

Recommended Posts

Posted
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:

HomerGun2.gif

  • Replies 33
  • Created
  • Last Reply

Top Posters In This Topic

  • todouble22

    12

  • Lee Mac

    8

  • ReMark

    6

  • CAB

    4

Top Posters In This Topic

Posted Images

Posted
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

Posted
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...

Posted

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))

Posted
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?

Posted
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?

Posted

Perhaps:

 

 (setq fullpath (FolderBox "Select top folder for File Delete:" nil 0))

Posted

Not sure if it will help, but the BrowseForFolder method that the "FolderBox" function uses is described here.

 

Lee

Posted
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

Posted
thanks cab and leeMac always appreciated

 

You're welcome Todd :)

Posted

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

Posted
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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...