import os
from args import args
def num_dir(num_each_dir):
"""
计算子文件夹内的文件个数
"""
# 输入num_each_dir为主文件夹路径(主文件夹内为n个子文件夹
# 初始化每个子文件夹内文件个数(共有args.num_classes个子文件夹
each_num = [0] * args.num_classes
# 将子文件夹名称输入列表
DirList = os.listdir(num_each_dir)
# 遍历主文件夹
for i, DirName in zip(range(args.num_classes), DirList):
# 子文件夹路径
DirName = num_each_dir + '/' + DirName
# 遍历子文件夹
if os.path.isdir(DirName):
FileList = os.listdir(DirName)
for _ in FileList:
each_num[i] += 1
return each_num
if __name__ == '__main__':
dirName = '../' + args.trainroot
num_dir(dirName)
09-16
2035
12-01
8707
01-26
1537