计算多个文件夹中,总文件个数(python)

    xiaoxiao2021-03-25  149

    # -*- 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)
    转载请注明原文地址: https://ju.6miu.com/read-3704.html

    最新回复(0)