Jump to content
andr3flaviano

Rename current open file

Recommended Posts

andr3flaviano

Hello, guys!

I need a lisp to rename the current open file. I already have a routine that takes the current file name and creates a string with the new file name (Just six numbers in the old name needs to change)... But I coudn't change the old name for the new name. I've tried to use the (Vl-File-Rename), but I think that i didn't use it right.... Here's go the code:

 

(defun C:changename (n1 n2 n3 n4 n5 n6)

 

(setq new_number (strcat (itoa n1)

(itoa n2)

(itoa n3)

(itoa n4)

(itoa n5)

(itoa n6)))

 

(setq old_name (strcat (getvar "DWGPREFIX") (getvar "DWGNAME")))

 

(setq size (strlen old_name))

 

(setq final (- size 18 )) ;

 

(setq start_name (substr old_name 1 final ))

 

(setq end_name (substr old_name (+ final 7) (- size final)))

 

(setq new_name (strcat start_name new_number end_name))

 

(alert old_name)

 

(alert new_name)

 

(vl-file-rename old_name new_name)

 

); end defun

 

 

The old name is: D:\Profiles\s-Andre.Almeida\Desktop\Autocad\3-157941-012-005.dwg

 

The new name, for example, could be: D:\Profiles\s-Andre.Almeida\Desktop\Autocad\3-666666-012-005.dwg

 

I just need to change the names with the (vl-file-rename)

 

could someone help me?

Edited by andr3flaviano

Share this post


Link to post
Share on other sites
Tharwat

Are you sure that you can rename a file currently opened?

Share this post


Link to post
Share on other sites
ReMark

I doubt you can rename a file while it is open. Why not choose instead to do a "saveas" under a new file name?

Share this post


Link to post
Share on other sites
SLW210

Please read the Code Posting Guidelines and edit your post to include the Code in Code Tags.

 

[NOPARSE]

Your Code Here

[/NOPARSE] =

Your Code Here

Share this post


Link to post
Share on other sites
marko_ribar

Here :

 

(setq end_name (substr old_name (+ final 7) (- size final)))

 

 

(- size final) is sufficient... You could just use :

 

(setq end_name (substr old_name (+ final 7)))

Share this post


Link to post
Share on other sites
andr3flaviano

Hmmmmm...

I thought that i could rename the opened file, but i will use the "Save as" so... Thank you, guys!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...