Refactored clean directory name code

This commit is contained in:
admin 2024-05-19 13:18:13 -04:00
parent 19e8c46c3e
commit 453a6c98a3
2 changed files with 13 additions and 12 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
test/

View File

@ -27,16 +27,7 @@ def count_folder_files(folder_path):
def check_directory_exists(directory_name):
return os.path.isdir(directory_name)
def main():
if len(sys.argv) != 2:
print("Usage: python script.py <folder_path>")
sys.exit(1)
directory_name = sys.argv[1]
suffix = count_folder_files(directory_name)
# If [num] already exists at the end of the string, remove it so we can update it
def clean_directory_name(directory_name):
# Find the last occurrence of backslash
last_backslash_index = directory_name.rfind('\\')
@ -45,11 +36,20 @@ def main():
# If '[' exists after the last backslash, remove everything after it
if last_open_bracket_index != -1:
directory_name_cleaned = directory_name[:last_open_bracket_index]
return directory_name[:last_open_bracket_index]
else:
# If '[' doesn't exist, keep the original string
directory_name_cleaned = directory_name
return directory_name
def main():
if len(sys.argv) != 2:
print("Usage: python script.py <folder_path>")
sys.exit(1)
directory_name = sys.argv[1]
suffix = count_folder_files(directory_name)
# If [num] already exists at the end of the string, remove it so we can update it
directory_name_cleaned = clean_directory_name(directory_name)
if check_directory_exists(directory_name):
print(f"Directory '{directory_name}' exists.")