diff --git a/rom_prepper.py b/rom_prepper.py index 7378331..d55664d 100644 --- a/rom_prepper.py +++ b/rom_prepper.py @@ -13,6 +13,15 @@ def load_path_config(): return paths +def get_language_abbreviation(file_name): + # Extract the language abbreviation from the file name + parts = file_name.split('(') + if len(parts) > 1: + language_abbreviation = parts[-1].split(')')[0] + return language_abbreviation.strip() + return '' + + def replicate_directory_structure(source_path:str, target_path:str, file_extensions, max_depth=None): for root, dirs, files in os.walk(source_path): # Get the relative path of the current directory @@ -29,8 +38,15 @@ def replicate_directory_structure(source_path:str, target_path:str, file_extensi # Copy files with the specified extensions to the target directory for file in files: if any(file.endswith(ext) for ext in file_extensions): - source_file = os.path.join(root, file) - target_file = os.path.join(corr_path, file) + source_file = os.path.join(root, file) + + # Extract the language abbreviation from the file name + language = get_language_abbreviation(file) + + # Generate the new file name + file_name, file_extension = os.path.splitext(file) + new_file_name = f"{file_name} ({language}){file_extension}" + target_file = os.path.join(target_dir, new_file_name) shutil.copy2(source_file, target_file) # Check if the maximum depth has been reached @@ -45,8 +61,16 @@ if __name__ == "__main__": # Read settings from the config file config = configparser.ConfigParser() config.read(config_file) + root_dir = pathlib.Path(__file__).parent.absolute() source_directory = config.get('Settings', 'source_root_dir') + source_dir_full = root_dir / source_directory + if not os.path.exists(source_dir_full): + pathlib.Path.mkdir(source_dir_full, exist_ok= True) target_directory = config.get('Settings', 'target_root_dir') + target_dir_full = root_dir / target_directory + if not os.path.exists(target_dir_full): + pathlib.Path.mkdir(target_dir_full, exist_ok= True) + max_depth = config.getint('Settings', 'max_depth') # Read file extensions from the config file