diff --git a/CountFolderFiles.py b/CountFolderFiles.py index c14b3e5..6588105 100644 --- a/CountFolderFiles.py +++ b/CountFolderFiles.py @@ -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