Renaming Files

I have been having a lot of trouble renaming some .dwfx files that I have exported for use in Navisworks. I got the exporter to work, but it it outputs the files with a 3DView prefix. I couldn’t find a way to remove that, so I have been attempting to rename the files retroactively. I found the archi-labs “rename.files” node, but I have been struggling to get it to work. I found another topic about pulling the python from the custom node to the workspace, but it doesn’t process the whole list.
So far I have gotten it to rename the first 4 files in the list before it returns an error. It doesn’t seem to be the files / filenames themselves, as when I delete the first 4 renamed files, the next 4 are renamed without trouble.!

Hi @bnydam42,

Try to feed the input Identifiers In[1] with a list of the previous filenames of DWFx.
It should work.


I went back through it and it works. I thought I had tried that, but I think that was before I pulled the python script out. I believe that the previous arrangement was returning a file already exists error…
Anyways, it works like this:

So I double checked, with the original archi-labs rename.file node I get this traceback error:
“Cannot create file when that file already exists”

Hi @bnydam42,

The original node archi-labs rename file as a problem with the inputs in the custom node.
The result is that it doesn’t accept list of files. You can modify it like in this topic :

If your script works, you can mark the topic as solved.


Sorry for adding to an old thread, but I was playing around with this node today… In my case, I had a folder of 200 files with a mix of pdfs & dwgs that had the same name…

I was getting a series of quite random fails and my fix was to ensure the renaming was defined by the extracted file.

For the example in this thread and for mine, the replacement was simple enough for this to be quite convenient…

Hopefully that is useful to someone.


# Copyright(c) 2016, Konrad Sobon
# @arch_laboratory,

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

import os

filePath = IN[0]

files = os.listdir(filePath)
errorReport = None

output = []

for file in files:
        currentFileName = filePath + "\\" + file
        if "dwg" in file:
            #trim off the revision and description and add the file type and DWG back
            newFileName = filePath + "\\" + file[:27] + "_DWG.dwg"
            os.rename(currentFileName, newFileName)
            #trim off the revision and description and add the file type back
            newFileName = filePath + "\\" + file[:27] + ".pdf"
            os.rename(currentFileName, newFileName)  
        # if error accurs anywhere in the process catch it
        import traceback
        errorReport = traceback.format_exc()

if errorReport == None:
    OUT = output
    OUT = errorReport

You all realize the OOTB node FileSystem.MoveFile can basically do renames right?

No need for custom packages. Simply, “move file” with a new name and delete the old one.


Hi John,

So I first need a node to read all the file names, then I edit the text, then I use a node to rename the files.

Unfortunately, if 2 files have the same name but different extensions (.pdf, .dwg) and I have a lot of them, the node reading the names eventually gets out of order with the node setting the name (even if using the same method in both nodes).

So I get an error ‘can’t name files with same name’.

So I switched to running with python and doing it all in 1 process.

Admittedly I didn’t try with the node you suggest, perhaps that’s better!

Hope that clarifies :slight_smile: Keep up all the great work!