Changed the rename to check for ' [' instead of '['. That way if there is a [ symbol in the directory already, it won't skip it unless it is using the same 2 space prefix. Also it looks cleaner to have it spaced out. May change it to a different prefix later.
This commit is contained in:
parent
bd9f268f52
commit
d64ec57b69
|
|
@ -7,7 +7,7 @@ def append_to_folder_name(folder_path, suffix):
|
|||
base_folder_name = os.path.basename(folder_path)
|
||||
|
||||
# Append the suffix to the folder name
|
||||
new_folder_name = f"{base_folder_name}[{suffix}]"
|
||||
new_folder_name = f"{base_folder_name} [{suffix}]"
|
||||
|
||||
# Rename the folder
|
||||
os.rename(folder_path, os.path.join(os.path.dirname(folder_path), new_folder_name))
|
||||
|
|
@ -62,7 +62,7 @@ def clean_directory_name(directory_name):
|
|||
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)
|
||||
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:
|
||||
|
|
@ -71,7 +71,7 @@ def clean_directory_name(directory_name):
|
|||
# If '[' doesn't exist, keep the original string
|
||||
return directory_name
|
||||
else:
|
||||
return directory_name.rsplit("[", 1)[0]
|
||||
return directory_name.rsplit(" [", 1)[0]
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
|
|
@ -88,7 +88,7 @@ def main():
|
|||
if check_directory_exists(directory_name):
|
||||
print(f"Directory '{directory_name}' exists.")
|
||||
|
||||
#If folder was counted already, remove the old count. Ex: dirname[1] -> dirname
|
||||
#If folder was counted already, remove the old count. Ex: dirname_[1] -> dirname
|
||||
os.rename(directory_name, os.path.join(os.path.dirname(directory_name), directory_name_cleaned))
|
||||
directory_name = directory_name_cleaned
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user