Removed pauses and debug text
This commit is contained in:
parent
94052659f6
commit
df65a72fa3
|
|
@ -13,7 +13,6 @@ def append_to_folder_name(folder_path, suffix):
|
||||||
# Rename the folder
|
# Rename the folder
|
||||||
os.rename(folder_path, os.path.join(os.path.dirname(folder_path), new_folder_name))
|
os.rename(folder_path, os.path.join(os.path.dirname(folder_path), new_folder_name))
|
||||||
print(f"Folder renamed to: {new_folder_name}")
|
print(f"Folder renamed to: {new_folder_name}")
|
||||||
os.system("pause")
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(f"Error: Folder '{folder_path}' not found.")
|
print(f"Error: Folder '{folder_path}' not found.")
|
||||||
os.system("pause")
|
os.system("pause")
|
||||||
|
|
@ -31,9 +30,7 @@ def count_subdirectories(path):
|
||||||
def count_folder_files(folder_path):
|
def count_folder_files(folder_path):
|
||||||
try:
|
try:
|
||||||
# If no subfolders exist, return the number of files in the folder
|
# If no subfolders exist, return the number of files in the folder
|
||||||
print("entering count_subdirectories")
|
|
||||||
num_subdirectories = count_subdirectories(folder_path)
|
num_subdirectories = count_subdirectories(folder_path)
|
||||||
print("exiting count_subdirectories")
|
|
||||||
if num_subdirectories == 0:
|
if num_subdirectories == 0:
|
||||||
|
|
||||||
# Count the number of files in the folder
|
# Count the number of files in the folder
|
||||||
|
|
@ -43,20 +40,17 @@ def count_folder_files(folder_path):
|
||||||
# If subdirectories do exist, return the number of files in each subdirectory then this directory
|
# If subdirectories do exist, return the number of files in each subdirectory then this directory
|
||||||
else:
|
else:
|
||||||
file_count = ""
|
file_count = ""
|
||||||
print("entering get_subdirectories")
|
|
||||||
subdirectories = get_subdirectories(folder_path)
|
subdirectories = get_subdirectories(folder_path)
|
||||||
for i, directory in enumerate(subdirectories):
|
for i, directory in enumerate(subdirectories):
|
||||||
file_count = file_count + str(sum(1 for entry in os.scandir(directory) if entry.is_file()))
|
file_count = file_count + str(sum(1 for entry in os.scandir(directory) if entry.is_file()))
|
||||||
#If there's another element, add a space (Keep code this way so that append folder files looks right)
|
#If there's another element, add a space (Keep code this way so that append folder files looks right)
|
||||||
if i != len(subdirectories) - 1:
|
if i != len(subdirectories) - 1:
|
||||||
file_count = file_count + " "
|
file_count = file_count + " "
|
||||||
print(file_count)
|
|
||||||
#Append the number of files in the folder unless if there are none
|
#Append the number of files in the folder unless if there are none
|
||||||
if (sum(1 for entry in os.scandir(folder_path) if entry.is_file()) > 0):
|
if (sum(1 for entry in os.scandir(folder_path) if entry.is_file()) > 0):
|
||||||
file_count = file_count + " " + str(sum(1 for entry in os.scandir(folder_path) if entry.is_file()))
|
file_count = file_count + " " + str(sum(1 for entry in os.scandir(folder_path) if entry.is_file()))
|
||||||
print(subdirectories)
|
print(subdirectories)
|
||||||
print(file_count)
|
print(file_count)
|
||||||
os.system("pause")
|
|
||||||
return file_count
|
return file_count
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -85,26 +79,19 @@ def clean_directory_name(directory_name):
|
||||||
return directory_name.rsplit(" [", 1)[0]
|
return directory_name.rsplit(" [", 1)[0]
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("program started")
|
|
||||||
print(sys.argv)
|
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print("Usage: CountFolderFiles <folder_path>")
|
print("Usage: CountFolderFiles <folder_path>")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
print(args)
|
|
||||||
os.system("pause")
|
|
||||||
for arg in args:
|
for arg in args:
|
||||||
directory_name = arg
|
directory_name = arg
|
||||||
print("entering count_folder_files")
|
|
||||||
suffix = count_folder_files(directory_name)
|
suffix = count_folder_files(directory_name)
|
||||||
# If [num] already exists at the end of the string, remove it so we can update it
|
# 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)
|
directory_name_cleaned = clean_directory_name(directory_name)
|
||||||
|
|
||||||
if check_directory_exists(directory_name):
|
if check_directory_exists(directory_name):
|
||||||
print(f"Directory '{directory_name}' exists.")
|
print(f"Directory '{directory_name}' exists.")
|
||||||
os.system("pause")
|
|
||||||
|
|
||||||
#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))
|
os.rename(directory_name, os.path.join(os.path.dirname(directory_name), directory_name_cleaned))
|
||||||
directory_name = directory_name_cleaned
|
directory_name = directory_name_cleaned
|
||||||
|
|
@ -112,7 +99,6 @@ def main():
|
||||||
append_to_folder_name(directory_name, suffix)
|
append_to_folder_name(directory_name, suffix)
|
||||||
else:
|
else:
|
||||||
print(f"Directory '{directory_name}' does not exist.")
|
print(f"Directory '{directory_name}' does not exist.")
|
||||||
os.system("pause")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user