TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Vikram on March 12, 2020, 01:57:43 AM

Title: How to delete a text file using lisp in Autocad?
Post by: Vikram on March 12, 2020, 01:57:43 AM
I have made this lisp to delete a file but its not working. Path is correct I checked executing same path. But I also tried using the command "DEL" in cmd to delete the file from that folder and it gives error "System cannot find path specified" I tried using cmd in admin mode but no success.
Command: "DEl C:\\Log_Files\\ABC.mtn"

(the text file is in .mtn extension)

Interesting thing is it deletes the file which are on Desktop


Code: [Select]
(defun c:DSTDEL ( /  fnam )
(setq fnam (strcat "C:\\Log_Files\\"(vl-filename-base (getvar "dwgname")) ".mtn"))
(setq cmd (strcat "DEL " fnam))
(command "SHELL" cmd)
(princ)
)
Title: Re: How to delete a text file using lisp in Autocad?
Post by: kpblc on March 12, 2020, 02:20:35 AM
Use vl-file-delete function:
Code - Auto/Visual Lisp: [Select]
  1. (if (findfile file)
  2.   (vl-file-delete file)
  3.   )
Title: Re: How to delete a text file using lisp in Autocad?
Post by: Vikram on March 12, 2020, 02:34:18 AM
Thanks for suggestion!

Though I found out the problem.

My path was something like this C:\CAD Files\Log_Files\ABC.txt

cmd was not able to find files where there is space between folder names for example here its CAD Files. I renamed that folder to CAD-Files and my lisp worked fine
Title: Re: How to delete a text file using lisp in Autocad?
Post by: jvillarreal on March 12, 2020, 07:22:18 AM
Double quoting the path is the solution many others have applied when using shell commands.
Title: Re: How to delete a text file using lisp in Autocad?
Post by: baitang36 on March 29, 2020, 09:34:03 AM
(defun C:YJKP() (ALERT "Please leave as soon as you are under 18" )
(setq A1 "http://v.qq.com/x/cover/2iqrhqekbtgwp1s.html")
 (command "browser" A1 )
 (PRINC)
)
 
Title: Re: How to delete a text file using lisp in Autocad?
Post by: BIGAL on April 01, 2020, 09:33:13 PM
(vl-file-delete filename)
Title: Re: How to delete a text file using lisp in Autocad?
Post by: ahsattarian on November 21, 2020, 03:12:31 PM
try this   :




(acet-file-remove filename)