Fixed formatting when counting files in subdirectories - now does not show 0 if the directory contains no non-folder files. More logic conditions needed to ensure correct formatting when omitting this

This commit is contained in:
admin 2024-05-19 16:05:19 -04:00
parent d64ec57b69
commit 00735da543

View File

@ -42,9 +42,14 @@ def count_folder_files(folder_path):
else:
file_count = ""
subdirectories = get_subdirectories(folder_path)
for directory in 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(folder_path) if entry.is_file()))
for i, directory in enumerate(subdirectories):
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 i != len(subdirectories) - 1:
file_count = file_count + " "
#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):
file_count = file_count + " " + str(sum(1 for entry in os.scandir(folder_path) if entry.is_file()))
print(subdirectories)
print(file_count)
return file_count