From d64ec57b69f5c1825cb7fb61158455f30203f28e Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 19 May 2024 15:46:47 -0400 Subject: [PATCH] Changed the rename to check for ' [' instead of '['. That way if there is a [ symbol in the directory already, it won't skip it unless it is using the same 2 space prefix. Also it looks cleaner to have it spaced out. May change it to a different prefix later. --- CountFolderFiles.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CountFolderFiles.py b/CountFolderFiles.py index 68b6005..c14b3e5 100644 --- a/CountFolderFiles.py +++ b/CountFolderFiles.py @@ -7,7 +7,7 @@ def append_to_folder_name(folder_path, suffix): base_folder_name = os.path.basename(folder_path) # Append the suffix to the folder name - new_folder_name = f"{base_folder_name}[{suffix}]" + new_folder_name = f"{base_folder_name} [{suffix}]" # Rename the folder os.rename(folder_path, os.path.join(os.path.dirname(folder_path), new_folder_name)) @@ -62,7 +62,7 @@ def clean_directory_name(directory_name): last_backslash_index = directory_name.rfind('\\') # Find the first occurrence of '[' after the last backslash - last_open_bracket_index = directory_name.find('[', last_backslash_index) + last_open_bracket_index = directory_name.find(' [', last_backslash_index) # If '[' exists after the last backslash, remove everything after it if last_open_bracket_index != -1: @@ -71,7 +71,7 @@ def clean_directory_name(directory_name): # If '[' doesn't exist, keep the original string return directory_name else: - return directory_name.rsplit("[", 1)[0] + return directory_name.rsplit(" [", 1)[0] def main(): if len(sys.argv) < 2: @@ -88,7 +88,7 @@ def main(): if check_directory_exists(directory_name): print(f"Directory '{directory_name}' exists.") - #If folder was counted already, remove the old count. Ex: dirname[1] -> dirname + #If folder was counted already, remove the old count. Ex: dirname_[1] -> dirname os.rename(directory_name, os.path.join(os.path.dirname(directory_name), directory_name_cleaned)) directory_name = directory_name_cleaned