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: