Sorry for the late reply, I managed to get the tool to work the way I needed it to. I’ll post the work here in case someone else in the future has the same issue.
your_folder_path = r'D:\Test'
old_path = 'S:/something/something/old_file_path/your_reference_file.ma'
new_path = "D:/something/something/more_stuff/your_reference_file.ma"
def remap_the_files(path, old_ref, new_ref):
list_of_items = os.listdir(path)
for item in list_of_items:
if os.path.isdir(os.path.join(path, item)): # Checks to see if this item is a folder (dir)
remap_the_files(os.path.join(path, item), old_path, new_path)
else:
if item.endswith('.ma'): # Checks to see if this item is a maya ascii file
print(os.path.join(path, item))
filepath = os.path.join(path, item)
with open(filepath, "r") as read_stream:
# Get all file contents in a list.
fileLines = read_stream.readlines()
# Use enumerate to keep track of what index we're at.
for i, line in enumerate(fileLines):
# Check if the line has the old path in it.
if old_ref in line:
# Replace with the new path and assign the change.
fileLines[i] = line.replace(old_ref, new_ref)
# Completely replace the file with our changes.
with open(filepath, 'w') as write_stream:
# You must pass the contents in here to write it.
write_stream.writelines(fileLines)
remap_the_files(your_folder_path, old_path, new_path)
print "Job Done..."
Thanks everyone for the help.