From 545279d6c6c28f1af39547ea1ae26e957dde09d4 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 19 May 2024 13:26:12 -0400 Subject: [PATCH] Now cleans files correctly whether or not there is a slash in the directory_name --- CountFolderFiles.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/CountFolderFiles.py b/CountFolderFiles.py index 9ffdb24..b9420ef 100644 --- a/CountFolderFiles.py +++ b/CountFolderFiles.py @@ -28,18 +28,21 @@ def check_directory_exists(directory_name): return os.path.isdir(directory_name) def clean_directory_name(directory_name): - # Find the last occurrence of backslash - last_backslash_index = directory_name.rfind('\\') + if '\\' in directory_name: + # Find the last occurrence of backslash + 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) + # Find the first occurrence of '[' after the last backslash + 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: - return directory_name[:last_open_bracket_index] + # If '[' exists after the last backslash, remove everything after it + if last_open_bracket_index != -1: + return directory_name[:last_open_bracket_index] + else: + # If '[' doesn't exist, keep the original string + return directory_name else: - # If '[' doesn't exist, keep the original string - return directory_name + return directory_name.rsplit("[", 1)[0] def main(): if len(sys.argv) != 2: