How to remove Model (1) from the end of a PDF

How to remove Model (1) from the end of a PDF

Camatties1984
Explorer Explorer
974 Views
1 Reply
Message 1 of 2

How to remove Model (1) from the end of a PDF

Camatties1984
Explorer
Explorer

Here is a  .bat program I wrote to remove Model (1) from the end of a pdf. For some reason AutoCAD loves putting it in the file name.

 

rename "* model (1).pdf" "* "

rename "* model" "* "

for /f "tokens=* delims= " %%i in ('dir /b/s/A-d') DO (

  if "%%~xi" == "" rename "%%~fi" "%%~ni.pdf"

)

 

I'm sure someone else has had this problem.

 

0 Likes
975 Views
1 Reply
Reply (1)
Message 2 of 2

jdiala
Advocate
Advocate

Here is mine

 

(defun C:rempdf (/ dir)
  (if
    (setq dir (LM:browseforfolder "Browse for a folder on where the PDF's are located. " nil 512))
    (mapcar
      (function 
        (lambda (x)
          (cond
            (
              (vl-string-search "Model (1)" x)
              (vl-file-rename 
                (strcat dir "\\" x) 
                (strcat dir "\\"
                  (vl-string-subst "" " Model (1)" x)
                )
              )
            )
            ( 
              (vl-string-search "-Model" x)
              (vl-file-rename 
                (strcat dir "\\" x) 
                (strcat dir "\\"
                  (vl-string-subst "" "-Model" x)
                )
              )
            )
          )
        )
      )
      (vl-directory-files dir "*Model*.pdf")
    )
  )
(princ)
)



;;------------------=={ Browse for Folder }==-----------------;;
;;                                                            ;;
;;  Displays a dialog prompting the user to select a folder.  ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2013 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  msg - message to display at top of dialog                 ;;
;;  dir - root directory (or nil)                             ;;
;;  flg - bit-coded flag specifying dialog display settings   ;;
;;------------------------------------------------------------;;
;;  Returns:  Selected folder filepath, else nil.             ;;
;;------------------------------------------------------------;;

(defun LM:browseforfolder ( msg dir flg / err fld pth shl slf )
    (setq err
        (vl-catch-all-apply
            (function
                (lambda ( / app hwd )
                    (if (setq app (vlax-get-acad-object)
                              shl (vla-getinterfaceobject app "shell.application")
                              hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
                              fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg flg dir)
                        )
                        (setq slf (vlax-get-property fld 'self)
                              pth (vlax-get-property slf 'path)
                              pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
                        )
                    )
                )
            )
        )
    )
    (if slf (vlax-release-object slf))
    (if fld (vlax-release-object fld))
    (if shl (vlax-release-object shl))
    (if (vl-catch-all-error-p err)
        (prompt (vl-catch-all-error-message err))
        pth
    )
)

(vl-load-com)