[RenamerOnUpdate] Move files fails when library is referenced via UNC
[Symptom] Can't use RenamerOnUpdate to move files and create folder structures when library uses UNC names (ie \library\share) - at least on Windows.
[Investigation] In-situ file renames work fine. Digging around a bit (and I'm no coder for sure!) it's because the code in RenamerOnUpdate.py funtion create_new_pathis expecting a ": " in the first position, and then builds a path after that. When no ":" is present, the resulting path is \library\share\folder which then doesn't match in the DB, resulting in DB update failure and roll back.
[Fix] At least for me was to add a bool assuming path was a UNC, setting that to False if a ":" was detected, but if it remained True, then simply appending two backslashes (\ - one is needed to escape the second). While this works for me, I've done no testing beyond triggering a move based on a tag, and I've not tested against a named drive.
@Wheeliewhee Can you show the code you used to make it work?
Within renamerOnUpdate.py, edit the function create_new_path with the three additions in shown by the remarks below - it still seems to work!
def create_new_path(scene_info: dict, template: dict):
# Create the new path
# Split the template path
path_split = scene_info["template_split"]
#ADDITION ONE
bUNC = True
#END ONE
path_list = []
for part in path_split:
if ":" in part and path_split[0]:
path_list.append(part)
#ADDITION TWO
bUNC = False
#END TWO
elif part == "$studio_hierarchy":
if not scene_info.get("studio_hierarchy"):
continue
for p in scene_info["studio_hierarchy"]:
path_list.append(re.sub('[\\/:"*?<>|]+', "", p).strip())
else:
path_list.append(
re.sub('[\\/:"*?<>|]+', "", makePath(scene_info, part)).strip()
)
# Remove blank, empty string
path_split = [x for x in path_list if x]
# The first character was a seperator, so put it back.
if path_list[0] == "":
path_split.insert(0, "")
if PREVENT_CONSECUTIVE:
# remove consecutive (/FolderName/FolderName/video.mp4 -> FolderName/video.mp4
path_split = remove_consecutive(path_split)
if "^*" in template["path"]["destination"]:
if scene_info["current_directory"] != os.sep.join(path_split):
path_split.pop(len(scene_info["current_directory"]))
path_edited = os.sep.join(path_split)
#ADDITION THREE
if bUNC:
path_edited = '\\' + path_edited
#END THREE
if FILENAME_REMOVECHARACTER:
path_edited = re.sub(f"[{FILENAME_REMOVECHARACTER}]+", "", path_edited)
# Using typewriter for Apostrophe
new_path = re.sub("[’‘”“]+", "'", path_edited)
return new_path```
Thanks @Wheeliewhee Unfortunately it does not work with my setup and I do not have the skills to figure out what is wrong. Edit: Since I only have UNC paths in my libraries, I took a chance and added the last line below to the original script. It seems to work fine, but since I have no idea what I am doing, it may mess up everything eventually.
if PREVENT_CONSECUTIVE:
# remove consecutive (/FolderName/FolderName/video.mp4 -> FolderName/video.mp4
path_split = remove_consecutive(path_split)
if "^*" in template["path"]["destination"]:
if scene_info["current_directory"] != os.sep.join(path_split):
path_split.pop(len(scene_info["current_directory"]))
path_edited = os.sep.join(path_split)
path_edited = '\\' + path_edited