您好,欢迎来到花图问答。
搜索
您的当前位置:首页python统计训练集下的图片个数

python统计训练集下的图片个数

来源:花图问答

-----------------------------------------------------------------------------------------------------

#统计 /home/dir/ 下的文件夹个数

import os

path ="home/dir"

count = 0

for fn in os.listdir(path): #fn 表示的是文件名

        count = count+1

print count

-----------------------------------------------------------------------------------------------------

获取文件夹下的文件的个数:

import os

path = os.getcwd()    #获取当前路径

count = 0

for root,dirs,files in os.walk(path):    #遍历统计

      for each in files:

            count += 1  #统计文件夹下文件个数

print count              #输出结果

-----------------------------------------------------------------------------------------------------

Copyright © 2019- huatuowenda.com 版权所有 湘ICP备2023022495号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务