Author Topic: delete Path..  (Read 3588 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
delete Path..
« on: April 05, 2005, 06:20:36 PM »
Hi,

i'm trying to remove some empty PATH..
i know there is (vl-mkdir "c:\allo\its me")

but how can i remove this path after ?

ther is no vl-remdir !!? :cry:

also, Doslib can help me with it...but don't want to load another arx just for getting a new function...

any idea ?
Keep smile...

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
delete Path..
« Reply #1 on: April 05, 2005, 07:15:39 PM »
Using Apropos in the VLIDE I see that Express Tools for 2002 has ACET-FILE-RMDIR

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
delete Path..
« Reply #2 on: April 05, 2005, 07:51:47 PM »
Well ... if you modify the code I wrote for you in this thread (you're welcome) you get this (first draft) --

Code: [Select]
(defun FindItemInFile ( PredicateFunction filename / handle item )

    ;;  © 2005 Michael Puckett

    (if
        (and
            (eq 'str (type filename))
            (setq handle (open filename "r"))
        )
        (vl-catch-all-apply
           '(lambda ( / stream )
                (while (setq stream (read-line handle))
                    (cond
                        (   (PredicateFunction stream)
                            (close handle)
                            (setq item stream)
                            (exit)
                        )
                    )
                )
                (close handle)
            )
        )
    )
    item
)


(defun HiddenShellInPgpFile ( / filepath filebackup handle )

    ;;  © 2005 Michael Puckett

    (or
        (FindItemInFile
            (lambda (stream)
                (wcmatch
                    (strcase (vl-string-trim " \t\n" stream))
                    "HIDDENSHELL`,`,4`,`*OS COMMAND:`,"
                )
            )
            (setq filepath (findfile "acad.pgp"))
        )
        (and
            filepath
            (setq filebackup (vl-filename-mktemp filepath))
            (vl-file-copy filepath filebackup)
            (setq handle (open filepath "a"))
            (princ "\nHiddenShell,,4,*OS Command:,\n" handle)
            (null (close handle))
            (setvar "re-init" 16)
        )
    )
)


(defun HiddenShell ( statement / cmdecho )

    ;;  © 2005 Michael Puckett

    (cond
        (
            (HiddenShellInPgpFile)
            (setq cmdecho (getvar "cmdecho"))
            (setvar "cmdecho" 0)
            (command "HiddenShell" statement)
            (setvar "cmdecho" cmdecho)
            t
        )
    )
)


(defun DeleteFolder ( foldername )

    ;;  © 2005 Michael Puckett

    (and
        (vl-file-directory-p foldername)
        ;;  use rmdir / s if you want to kill
        ;;  the entire tree but be careful!
        (HiddenShell (strcat "rmdir " foldername))
        (null (vl-file-directory-p foldername))
    )    
   
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

nivuahc

  • Guest
delete Path..
« Reply #3 on: April 05, 2005, 11:21:46 PM »
Moved to the appropriate forum.

Andrea

  • Water Moccasin
  • Posts: 2372
delete Path..
« Reply #4 on: April 06, 2005, 03:09:47 PM »
Quote from: MP
Well ... if you modify the code I wrote for you in this thread (you're welcome) you get this (first draft) --

Code: [Select]
(defun FindItemInFile ( PredicateFunction filename / handle item )

    ;;  © 2005 Michael Puckett

    (if
        (and
            (eq 'str (type filename))
            (setq handle (open filename "r"))
        )
        (vl-.......
   
)


wow !!  only for removing a folder ?
there is no thing...alittle shorter ?
Keep smile...

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
delete Path..
« Reply #5 on: April 06, 2005, 04:01:11 PM »
Quote from: Andrea
there is no thing...alittle shorter ?

Quote
C:\Temp>help rmdir
Removes (deletes) a directory.

RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path


    /S      Removes all directories and files in the specified directory
            in addition to the directory itself.  Used to remove a directory
            tree.

    /Q      Quiet mode, do not ask if ok to remove a directory tree with /S
TheSwamp.org  (serving the CAD community since 2003)

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
delete Path..
« Reply #6 on: April 08, 2005, 06:55:23 PM »
Here's another method that is pretty darn quick......and potentially dangerous, as it doesn't care if there are files in the folder or not...it will be deleted regardless.
Code: [Select]

(defun vl-rmdir (path / fso)
  (setq fso (vla-getinterfaceobject (vlax-get-acad-object) "Scripting.FileSystemObject"))
  (vlax-invoke fso 'deletefolder path 0)
  (vlax-release-object fso)
  )


edited to localize the fso symbol

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
delete Path..
« Reply #7 on: April 08, 2005, 06:58:53 PM »
Jeff that's sweet. I thought going that route would throw a security alert but it doesn't. Very nicely done.

<TippingHat.mpg>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst