Author Topic: vl-file-delete  (Read 2089 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
vl-file-delete
« on: March 24, 2005, 07:57:21 PM »
Why won't
Code: [Select]
(vl-file-delete (strcat SCR_NAME)) delete the file in this code when the lisp is done?

I tried using vl-filename-mktemp but it wasn't working either?

Code: [Select]
(defun C:RUN-ENDIT-BATCH (/ FULL_NAME LOG_NAME FNAME_DIR FNAME_LIST SCR_NAME FILE IN P dpath)

(setq dpath (getvar 'dwgprefix))
  (setq FULL_NAME (getfiled "Select A Drawing File - All DWG Files Will Be Super Purged In This Directory!!" (strcat dpath) "dwg" 8))
  (if FULL_NAME (progn
    (setq LOG_NAME (getvar "loginname"))
    (setq FNAME_DIR (vl-filename-directory FULL_NAME))
    (setq FNAME_LIST (vl-directory-files FNAME_DIR "*.dwg"))
    (setq P "\"")


    ;;; Write script File
    (if FNAME_LIST (progn
      (setq SCR_NAME (strcat FNAME_DIR "\\" "cleanup.scr"))
      (setq FILE (open SCR_NAME "w"))
      (setq IN 0)
      (repeat (length FNAME_LIST)
        (setq FNAME (nth IN FNAME_LIST))
        (setq FNAME (vl-filename-base FNAME))
        (write-line (strcat "_.open " P FNAME_DIR "\\" FNAME P) FILE)
        (write-line (strcat "(setvar 'clayer " P "0" P ")" ) FILE)
        (write-line "_.audit _y" FILE)
        (write-line "_.qsave" FILE)
        (write-line "enditbatch" FILE)
        (write-line "_.close _n" FILE)
       (setq IN (1+ IN))
      );;repeat
      (close FILE)

      (command "_.script" SCR_NAME)
      )
    )
  )
)
  (princ)
(vl-file-delete (strcat SCR_NAME))
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
vl-file-delete
« Reply #1 on: March 24, 2005, 08:36:08 PM »
As a quick test, comment out the line that actually runs the script: (command ..... )
Then try running the lisp again. If it now deletes the file, then I would have to assume that the script is still running when you are trying to delete it. Try adding a (while (> (getvar "cmdactive") 0), or something to wait for the script to finish.