Refactored clean directory name code
This commit is contained in:
parent
19e8c46c3e
commit
453a6c98a3
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
test/
|
||||
|
|
@ -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.")
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user