How to delete a file from plain Lisp?
I normally use this line to delete a file from Lisp:
(command "shell" (strcat "del " "1run.txt"))
I want to use a specify a drive also, like this:
(command "shell" (strcat "del " "H:/1run.txt"))
But it does not work. The file is not deleted.
I am using Bricscad V6, so I assume that the VL delete function is not usable.
Does anyone know how I can solve this?
Comments
-
On my system I have to use "\\" instead of "/":
(command "shell" (strcat "del " "C:\\1run.txt"))0 -
The use of "\\" in stead of "/" I have tried - witout any success.
But thanks for the suggestion anyway.
0 -
Svend,
I think you will find Roy's advice is correct. There are a number of possible reasons why your routine may not be working. I suggest that you break it down into parts so that you can see what is going on. Two key things that I would look at:- Does the file actually exist. I would add a check into your LISP to confirm that the file exists. Doing this will also provide the path portion by default.
- Do you have the correct syntax when calling the DEL command. I would call a simple batch instead adding a PAUSE so you can see what is going on.
[code](defun DELETEFILE (myfilename / file2del )
(if (setq file2del (findfile myfilename))
(command "shell" (strcat "SHELLDELETE " file2del))
(princ (strcat "\n" myfilename " not found"))
)
(prin1)
)[/code]
or
[code](defun C:DELETEFILE ( / file2del )
(if (setq file2del (getfiled "Select File to DELETE" "" "" 0))
(command "shell" (strcat "SHELLDELETE " file2del))
(princ "\nNo File selected")
)
(prin1)
)[/code]
SHELLDELETE.BAT would be something like:
[code]@echo OFF
DEL %1
PAUSE[/code]
In testing the above, I could see why the DEL command wasn't working.
Regards,Jason Bourhill
0 -
Thanks for your suggestions.
I will try these suggestions out and see if I can succeed with one.
0 -
Dear All,
here is another way to delete a file, without using (command) or _shell :-)
[code]
(defun DELETEFILE (myfilename / file2del )
(if (setq file2del (findfile myfilename))
(vl-file-delete file2del))
(princ (strcat "\n" myfilename " not found"))
)
(prin1)
)
[/code]
and similar for interactive mode as from Jason's sample.
Many greetings to all, Torsten0 -
Hi again. I have now had time to try the suggestions.
Please remeber it Bricscad V6 I am usig for this.
I have tracked it down to that the command "shell" gives an error: "Error using shell command".
I use :
(command "shell" (strcat "SHELLDELETE " file2del))file2del variable is containg the correct filename "H:\\1run..txt"
SHELLDELETE.BAT is located in the program folder.If I use the command shell in Bricscad I get the prompt "DOS Command:"
When typing any DOS command is answers with the same "Error using shell command"Any other suggestions?
0 -
With BC7+WinXP I don't experience this problem. Could it be a Windows rights issue? Can you use DOS commands in a DOS box?0
-
Please note it is BC6 + W7. It is not Windows rights as it is my own PC and my own Home dir I wnat to delete from.
I can use DOS commands from a DOS box, yes.
0 -
Perhaps this is a path issue. You could try changing the Windows' path to include the folder where cmd.exe resides.0
-
I am not quite sure what you mean....
When I have BC6 opened and use the command SHELL at the command line I get the prompt "DOS Shell:"
If I then just press ENTER I get the cmd window (black window with default path.
When I here use "del h:\1run.txt" the file is deleted as supposed.
0 -
Have you thought about using DOSLib ??0
-
Yes I have, but I cannot find it for Bricscad V6. -((
0 -
Just download this version: DOSLib 4.4 for AutoCAD Release 13-14.
The file doslib4.dll can be used for BC7 and, I am pretty certain, also for BC6.0