andr3flaviano Posted October 21, 2016 Posted October 21, 2016 (edited) 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 October 21, 2016 by andr3flaviano Quote
Tharwat Posted October 21, 2016 Posted October 21, 2016 Are you sure that you can rename a file currently opened? Quote
ReMark Posted October 21, 2016 Posted October 21, 2016 I doubt you can rename a file while it is open. Why not choose instead to do a "saveas" under a new file name? Quote
SLW210 Posted October 21, 2016 Posted October 21, 2016 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 Quote
marko_ribar Posted October 21, 2016 Posted October 21, 2016 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))) Quote
andr3flaviano Posted October 21, 2016 Author Posted October 21, 2016 Hmmmmm... I thought that i could rename the opened file, but i will use the "Save as" so... Thank you, guys! Quote
Recommended Posts
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.