Author Topic: Rename a folder with Lisp  (Read 3344 times)

0 Members and 1 Guest are viewing this topic.

Rabbit

  • Guest
Rename a folder with Lisp
« on: June 15, 2012, 05:20:58 PM »
After searching all over, I can't figure out how to rename a folder with lisp.  Maybe my search criteria was wrong.

Basically, I want to rename a folder <C:Folder/Folder2> to <C:Folder/Folder3>.

Thanks,
Rabbit

BlackBox

  • King Gator
  • Posts: 3770
Re: Rename a folder with Lisp
« Reply #1 on: June 15, 2012, 05:30:30 PM »
I don't have CAD open right now, but I believe you're after vl-File-Rename (if memory serves).

** Edit - Actually, I think I use FileSystemObject for directories. Sorry for any confusion.
"How we think determines what we do, and what we do determines what we get."

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Rename a folder with Lisp
« Reply #2 on: June 15, 2012, 05:34:46 PM »
Code - Auto/Visual Lisp: [Select]
  1. (vl-file-rename "C:\\Folder\\Folder2" "C:\\Folder\\Folder3")

Always do a quick search before starting a new thread  :-)

Rabbit

  • Guest
Re: Rename a folder with Lisp
« Reply #3 on: June 15, 2012, 05:49:37 PM »
I had seen vl-file-rename, but it's misleading.  I thought that it was for files only.

Sorry for the trouble guys.
I'll go check it out.
Rabbit

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Rename a folder with Lisp
« Reply #4 on: June 15, 2012, 05:52:57 PM »
This is what I have used in the past ... apparently the vl-file-rename works too ;-) cool

Code: [Select]
(defun renFolder(OldName NewName)
  (setq fso (vlax-create-object "Scripting.FileSystemObject"))
  (setq ofe (vlax-invoke-method fso 'FolderExists OldName))
  (setq nfe (vlax-invoke-method fso 'FolderExists NewName))
  (if (and (= ofe :vlax-true)(= nfe :vlax-false))
    (vlax-invoke-method fso 'MoveFolder OldName NewName)
  )
  (and (= ofe :vlax-true)(= nfe :vlax-false)(= (vlax-release-object fso) 0))
)

Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

BlackBox

  • King Gator
  • Posts: 3770
Re: Rename a folder with Lisp
« Reply #5 on: June 15, 2012, 06:16:00 PM »
I don't have CAD open right now, but I believe you're after vl-File-Rename (if memory serves).

Code - Auto/Visual Lisp: [Select]
  1. (vl-file-rename "C:\\Folder\\Folder2" "C:\\Folder\\Folder3")


Thanks for the confirmation, Lee.  :-)

** Edit - Actually, I think I use FileSystemObject for directories. Sorry for any confusion.

This is what I have used in the past ... apparently the vl-file-rename works too ;-) cool

Code: [Select]
(defun renFolder(OldName NewName)
  (setq fso (vlax-create-object "Scripting.FileSystemObject"))
  (setq ofe (vlax-invoke-method fso 'FolderExists OldName))
  (setq nfe (vlax-invoke-method fso 'FolderExists NewName))
  (if (and (= ofe :vlax-true)(= nfe :vlax-false))
    (vlax-invoke-method fso 'MoveFolder OldName NewName)
  )
  (and (= ofe :vlax-true)(= nfe :vlax-false)(= (vlax-release-object fso) 0))
)

Two for two (from memory that is)!  :lmao:

I had seen vl-file-rename, but it's misleading.  I thought that it was for files only.


To add to your confusion, also consider the Getfiled, and Findfile functions.  ;-)

Simple example of the latter:

Code: [Select]
(findfile "C:\\Windows")
"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: Rename a folder with Lisp
« Reply #6 on: June 15, 2012, 06:22:08 PM »

To add to your confusion...

[SlightlyOffTopic]

vl-Registry-Write being relegated to string values always bothered me, yet this post accurately represents the level of documentation Autodesk has provided over the years:

http://forums.augi.com/showthread.php?139901-Do-this-if-the-drawing-name-is-equal-to-this&p=1175457&viewfull=1#post1175457

[/SlightlyOffTopic]
"How we think determines what we do, and what we do determines what we get."