import os
from collections import defaultdict
def analyze_file_formats(directory):
file_formats = defaultdict(list)
for root, _, files in os.walk(directory):
for file in files:
file_extension = os.path.splitext(file)[1]
file_formats[file_extension].append(os.path.join(root, file))
for file_format, paths in file_formats.items():
print("文件格式: {}, 数量: {}".format(file_format or '无扩展名', len(paths)))
for path in paths:
print(" 路径: {}".format(path))
if __name__ == "__main__":
directory_to_analyze = "/home"
analyze_file_formats(directory_to_analyze)