(defun c:SAV ( / nChkForDirs nChkForFiles cFNCurrVer cPadZero cSubd cSubdFN cSrcFN c_OldDir nVarEXPERT nMaxDateStrLen)
(setq cSubd "_Old")
(setq cSrcFN (strcat (getvar "dwgprefix") (getvar "dwgname")))
(setq nMaxDateStrLen 15)
(setq nVarEXPERT (getvar "expert"))
(setvar "expert" 5)
; vl-directory-files options
(setq nChkForDirs -1 nChkForFiles 1)
; Make the Filename
(setq
cFNCurrVer (strcat (car (parse (getvar "dwgname") ".")) "_" (STD-STRING-RIGHT-PAD-CHAR (rtos (getvar "CDATE") 2 6) nMaxDateStrLen "0"))
cSubdFN (strcat (getvar "dwgprefix") cSubd "\\" cFNCurrVer ".dwg")
)
; Save the dwg and copy it.
(prompt "\nSaving...")
(command ".save" "")
; Make the subdir
(MkSubDir cSubd)
(prompt (strcat "\nCopying to " cSubdFN))
(if (not (vl-file-copy cSrcFN cSubdFN))
(prompt (strcat "\nError copying " cSubdFN)))
(setvar "expert" nVarEXPERT)
(princ)
)
; Utility functions
(defun STD-STRING-RIGHT-PAD-CHAR (s n char)
(while (< (strlen s) n) (setq s (strcat s char)))
;;(substr s 1 n)
s
)
(defun MkSubDir (cDirName / cDir)
(setq cDir (vl-directory-files "" cDirName -1))
(if (not cDir)
(progn
(vl-mkdir (strcat ".\\" cDirName))
(vl-directory-files "" cDirName -1)))
)
(defun parse (str delim / out pos)
(setq delim (ascii delim))
(while (setq pos (vl-string-position delim str))
;(if (> pos 0);not just adjacent delimiters
(setq out (cons (substr str 1 pos) out))
(setq str (substr str (+ 2 pos)))
)
;(if (> (strlen str) 0);not a trailing delimiter
(reverse (cons str out))
;(reverse out)
)