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)
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: