CommunityScripts
CommunityScripts copied to clipboard
[renamerOnUpdate] files on multiple drives
When moving files across different drives, I must manually adjust the path template to reflect the correct destination within the same drive.
Implement a feature that automatically adjusts the file path to ensure files are moved within the same drive.
Proposed solution
This feature could analyze the current file path and compare it against a specified base directory. If the file is located in a different drive, the application would automatically adjust the path to ensure the file is moved to a location within the same drive, adhering to the specified base directory.
# Example path: 'C:\Users\{base_dir}\path\to\file', template: 'template\path'
# Result: 'C:\Users\{base_dir}\template\path'
base_dir = 'nsfw'
BASE_DIR = config.base_dir
if BASE_DIR is not None:
path_edited = create_new_path_with_base_dir(scene_info["current_directory"], template["path"]["destination"], BASE_DIR)
def create_new_path_with_base_dir(path: str, template: str, base_dir: str) -> str:
if BASE_DIR is None:
return template
# Split the path into its components
path_parts = path.split(os.sep)
# Check if BASE_DIR is in the path
if BASE_DIR in path_parts:
# Find the index of BASE_DIR in the path
base_dir_index = path_parts.index(BASE_DIR)
# Prepend the path up to BASE_DIR to the template
new_path = os.sep.join(path_parts[:base_dir_index+1]) + os.sep + template
else:
# If BASE_DIR is not in the path, return the template as is
new_path = template
return new_path