Change the file name(using prefix as an example)

I‘ve been using an useful tool called “拖把更名器” for many years,it’s really useful,I have a lot scenarios like change pdf sheets names,today I just want to attribute to the author and I found many one want to do it also,here’s a link(it‘s in Chinese,you can use google translate)
https://www.v2ex.com/t/824575
I want to use dynamo to repeat the process,I know it can be done.However it’s until today that I know the node called “Rename files”from the package “archilab” doesn’t work.So I search the froum and do it myself.Here’s a post which help me finish it.
https://forum.dynamobim.com/t/renaming-files/19435/8?u=john
And I also make youtube videos to record the process of learning and using dynamo,here’s the link.
https://youtu.be/ABB_SUXs9Yo
CHANGE FILE PRIFIX

Hi John,

It is still possible to use the archilab code in a python node and it works perfectly.

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

import os

filePath = IN[0]
identifiers = IN[1]
newNames = IN[2]
RunIt = IN[3]

files = os.listdir(filePath)

if RunIt:
	try:
		errorReport = None
		for file in files:
			currentFileName = filePath + "\\" + file
		
			for i, j in zip(identifiers, newNames):
				newFileName = filePath + "\\" + j
	
				if i in file and currentFileName != newFileName:
					os.rename(currentFileName, newFileName)
	except:
		# if error accurs anywhere in the process catch it
		import traceback
		errorReport = traceback.format_exc()
else:
	errorReport = "Set RunMe to True."

#Assign your output to the OUT variable
if errorReport == None:
	OUT = "Succesfully renamed."
else:
	OUT = errorReport

Just have to watch your inputs.
Here is an example of code to rename exported viewpoints from NavisWorks.

Hope this helps.


sorry it still doesn’t work for me,is it because I don’t have IronPython 2.7 in “C:\Program Files (x86)”?
Anyway thanks for your reply.

Oh, it’s just because you are using a newer version of Dynamo.
I believe the dynamo team said they are no longer using IronPython and instead transitioning to CPython.

The only thing you need to do for this version to work is to install the DynamoIronPython2.7 Package and change the engine to IronPyton2 in the Python Script.

Hope this is it. :smiley:

I hope Autodesk can fix the compatibility issue in the future.

Hi @John ,

You could also use the OOTB nodes called CopyFile and DeleteFile afterwards, just make sure to add a Transaction.End node after the CopyFile node

I once thought I need to copy file to new folder and then rename them,at last delete old files.But I found the node can overwrite it,so it won’t be necessary,thanks for your relply anyway.

1 Like