Now cleans files correctly whether or not there is a slash in the directory_name

This commit is contained in:
admin 2024-05-19 13:26:12 -04:00
parent 453a6c98a3
commit 545279d6c6

View File

@ -28,18 +28,21 @@ def check_directory_exists(directory_name):
return os.path.isdir(directory_name) return os.path.isdir(directory_name)
def clean_directory_name(directory_name): def clean_directory_name(directory_name):
# Find the last occurrence of backslash if '\\' in directory_name:
last_backslash_index = directory_name.rfind('\\') # Find the last occurrence of backslash
last_backslash_index = directory_name.rfind('\\')
# Find the first occurrence of '[' after the last backslash # 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 '[' exists after the last backslash, remove everything after it
if last_open_bracket_index != -1: if last_open_bracket_index != -1:
return directory_name[:last_open_bracket_index] return directory_name[:last_open_bracket_index]
else:
# If '[' doesn't exist, keep the original string
return directory_name
else: else:
# If '[' doesn't exist, keep the original string return directory_name.rsplit("[", 1)[0]
return directory_name
def main(): def main():
if len(sys.argv) != 2: if len(sys.argv) != 2: