Author Topic: How to delete a text file using lisp in Autocad?  (Read 677 times)

0 Members and 1 Guest are viewing this topic.

Vikram

  • Newt
  • Posts: 42
How to delete a text file using lisp in Autocad?
« 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)
)
« Last Edit: March 12, 2020, 02:04:48 AM by Vikram »

kpblc

  • Bull Frog
  • Posts: 363
Re: How to delete a text file using lisp in Autocad?
« Reply #1 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.   )
Sorry for my English.

Vikram

  • Newt
  • Posts: 42
Re: How to delete a text file using lisp in Autocad?
« Reply #2 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

jvillarreal

  • Bull Frog
  • Posts: 322
Re: How to delete a text file using lisp in Autocad?
« Reply #3 on: March 12, 2020, 07:22:18 AM »
Double quoting the path is the solution many others have applied when using shell commands.

baitang36

  • Newt
  • Posts: 67
Re: How to delete a text file using lisp in Autocad?
« Reply #4 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)
)
 

BIGAL

  • Swamp Rat
  • Posts: 551
  • 30 + years of using Autocad
Re: How to delete a text file using lisp in Autocad?
« Reply #5 on: April 01, 2020, 09:33:13 PM »
(vl-file-delete filename)
A man who never made a mistake never made anything

ahsattarian

  • Newt
  • Posts: 26
Re: How to delete a text file using lisp in Autocad?
« Reply #6 on: November 21, 2020, 03:12:31 PM »
try this   :




(acet-file-remove filename)