# -*- coding: utf-8 -*-
# Time:2017.03.28
# Author:coplin
# Function:Count the number of image file.
import os
def eachFile(PATH):
pathDir = os.listdir(PATH)
SUM=0
infolist=""
for allDir in pathDir:
child = os.path.join('%s%s%s' % (PATH,'/',allDir))
SUM+=len(os.listdir(child))
infolist+='\n'+allDir+':'+str(len(os.listdir(child)))
print infolist,"\nallNumber:"+str(SUM)
#write data to file(.txt)
priceFile = file(PATH+".txt", "w+")
priceFile.writelines(str(infolist))
priceFile.writelines("\nallNumber:" + str(SUM))
priceFile.close()
print "writeFile success!"
if __name__ == '__main__':
PATH = "./data"
print eachFile(PATH)
计算多个文件夹中,总文件个数(python)
最新推荐文章于 2023-07-30 00:13:47 发布