Maya WindowsError: [Error 32]


Hi all,
I have a Python script that loads the contents of a directory into a tableWidget and does a rename to convert UDIM naming conventions (Mari to Mudbox, Mudbox to Mari etc).

I’m using os.rename to rename files and it would occasionally fail with the error:
WindowsError: [Error 32] The process cannot access the file because it is being used by another process

I think I’ve tracked it down to the fact that I use fileDIalog2 to set the directory and occasionally I would mistakenly select a file rather than the directory, which caused the rename to fail as Maya has a hook on the image to display the preview when selected in the file dialog.

A workaround for the moment is to set the fileDialog2 “fileFilter” to None which prevents any file from being accidentally selected.

I was wondering if there’s a better way to fix this, ideally to make the Maya process let go of a file if it has been selected?