Author Topic: Deleteing a file without using Vl-file-delete  (Read 7024 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Deleteing a file without using Vl-file-delete
« on: November 25, 2005, 04:31:08 AM »
Is it possible to delete a file without using the vl-file-delete command?

I'm trying to create a lisp to move, copy and delete files using only plain lisp.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Deleteing a file without using Vl-file-delete
« Reply #1 on: November 25, 2005, 04:57:59 AM »
Have a look in your .PGP file ;
there should be this line :

DEL,      DEL,            8,*File to delete:,

if not, add it in the external command section

then, something like this  :
Code: [Select]
(defun c:MyDeleteFile ( / df)
 (setq df (getstring "\nDelete file: "))
 (command "DEL" df))
)



kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Deleteing a file without using Vl-file-delete
« Reply #2 on: November 25, 2005, 05:01:18 AM »
<warning.wav>

.. Test that carefully, it was done on the fly from an old memory .. assume all the 'normal' caveats apply.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Fatty

  • Guest
Re: Deleteing a file without using Vl-file-delete
« Reply #3 on: November 25, 2005, 06:25:57 AM »
<warning.wav>

.. Test that carefully, it was done on the fly from an old memory .. assume all the 'normal' caveats apply.



              Hi Kerry Brown

       Unfortunately, I did not found command "Delete" in Command Reference
       If 'delete' is loaded in command line I have a got return like this:
       _vlide delete Unknown command "DELETE".
       
       I'm not sure, but maybe following one will work for you (tested in A2005) :


       
Code: [Select]
        (setvar "cmdecho" 0)
        (setq fname
     (getfiled "Pick file to delete" (getvar "dwgprefix") "txt" 16)))       
(command "._del" fname)
        (setvar "cmdecho" 1)
        (gc)
       

         Thank you

         Fatty

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Deleteing a file without using Vl-file-delete
« Reply #4 on: November 25, 2005, 06:54:16 AM »
Hi Fatty,

Why would you enter DELETE at the command line ?

Just tested .. The code I posted works for me < after I fixed the parethhesis balancing :) >

Command: MYDELETEFILE
Delete file: c:\testDelete.TXT
Command: nil

The "._DEL" would be better, yes. :)

If the file name is set Programmatically, the (getfiled wont be needed, and can't be relied on to return the filename string.

Perhaps a test using something like this would help :-
(if (setq fnamex (findfile fname) (command "._del" fnamex) (alert "Error .. bla bla ") )

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Fatty

  • Guest
Re: Deleteing a file without using Vl-file-delete
« Reply #5 on: November 25, 2005, 07:49:01 AM »
Quote

If the file name is set Programmatically, the (getfiled wont be needed, and can't be relied on to return the filename string.

Perhaps a test using something like this would help :-
(if (setq fnamex (findfile fname) (command "._del" fnamex) (alert "Error .. bla bla ") )



      Hi  Kerry Brown

      Of course your example would be better I think,
      Thanks for explanation,
      Regards,

      Fatty

SMadsen

  • Guest
Re: Deleteing a file without using Vl-file-delete
« Reply #6 on: November 25, 2005, 08:35:18 AM »
One could also employ a FileSystemObject object but it pretty much corresponds to VL-FILE-DELETE and doesn't fit into what you'd call "plain lisp"

Code: [Select]
(defun delfile (/ fp fso)
  (cond
    ((setq fp (getfiled "" "" "" 4))
     (and (setq fso (vlax-create-object "Scripting.FileSystemObject"))
          ;; Invoke DeleteFile. Last arg is force-delete of read-only files
          (not (vlax-invoke-method fso "DeleteFile" fp :vlax-true))
          (if (not (vlax-object-released-p fso))
            (vlax-release-object fso)
          )
          (not (findfile fp))
     )
    )
  )
)
« Last Edit: November 25, 2005, 08:40:02 AM by SMadsen »

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Deleteing a file without using Vl-file-delete
« Reply #7 on: November 25, 2005, 04:52:08 PM »
Is it possible to delete a file without using the vl-file-delete command?

I'm trying to create a lisp to move, copy and delete files using only plain lisp.

Why you don't want to use vl-file delete ?

you can also use batch file
eg:

Code: [Select]
(setq file1 (open "c:\\application.bat" "w"))
(write-line "echo off" file1)
(write-line "del /f c:\\test.txt" file1)
(close file1)

but be careful with this....see the del /? dos options.
Keep smile...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Deleteing a file without using Vl-file-delete
« Reply #8 on: November 25, 2005, 05:11:00 PM »
Hudster,
Is this for ProgeCAD ?

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

hudster

  • Gator
  • Posts: 2848
Re: Deleteing a file without using Vl-file-delete
« Reply #9 on: November 28, 2005, 03:44:47 AM »
no, I wrote this lisp to copy a file, bind it and purge it and delete the original.

Code: [Select]
;;; TITLE:issdwg.lsp
;;;
;;; Copyright (C) 2005 by Andy Hudson
;;;
;;; Permission to use, copy, modify, and distribute this
;;; software and its documentation for any purpose and without
;;; fee is hereby granted
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR
;;; IMPLIED WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY
;;; PARTICULAR PURPOSE AND OF MERCHANTABILITY ARE HEREBY
;;; DISCLAIMED.
;;;
;;; Andy Hudson
;;; April 2005
;;;
;;;-------------------------------------------------------------
;;; Description:
;;;
;;; Routine to make Issuing a drawing comply with Rybka Standards
;;; The routine Moves the file to the Issued folder to ensure
;;; current drawings remain in the current folder, with a copy
;;; made and bound in the issued folder.
;;;
;;;-------------------------------------------------------------
;;; COMMAND
;;; issdwg
;;;-------------------------------------------------------------
;;;
;;error checker from www.afralisp.com
;;;
(LOAD "R:/DWG/aids/blocks/rybka_blocks/lisps/ERROR.LSP")
;;
(DEFUN C:issdwg (/ dirname newdirname filename origfile oldfiledia newfile issname issdir issfile)
  ;;GET DIRECTORY INFORMATION
  (SETQ dirname (GETVAR "DWGPREFIX")
newdirname (VL-STRING-TRIM "\\Mods" dirname)
filename (getvar "dwgname")
origfile (strcat dirname filename))
  ;;save the drawing
  (setq oldfiledia (getvar "filedia"))
  (setvar "filedia" 0)
  (setq newfile (strcat newdirname "\\" filename))
(if (findfile newfile)
(alert (strcat "File " newfile  " already exists In Folder! "))
(progn
(princ (strcat "\nSaving: " Newfile "\n" ))
  (command "._saveas" "" newfile)
);progn
);if
  (setvar "filedia" oldfiledia)
  ;;Save to issued folder
  ;;Create Directory & File Information
  (setq issname (vl-string-trim "current" newdirname))
  ;;create Issued folder
  (setq issdir (strcat issname "Issued"))
  (vl-mkdir issdir)
  ;;create issue file
  (Setq issdir (vl-string-subst "Issued" "current\\Mods" dirname))
  (setq issfile (strcat issdir filename))
  ;;save the file
  (command "._saveas" "" issfile)
  (command "-xref" "bind" "*")
  (command "-purge" "all" "*" "n")
  (command "-purge" "all" "*" "n")
  (command "-purge" "all" "*" "n")
  (command "-purge" "all" "*" "n")
  (command "-purge" "all" "*" "n")
  (command "qsave")
  ;;delete the old file
  (vl-file-delete origfile)
  (princ)
  )
  (PROMPT "\n Issue Drawing Lisp loaded, enter issdwg to run.")
  (princ)

I was just wondering if there was another way to delete the file without using VL.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue