遞迴統計檔案個數--python
阿新 • • 發佈:2019-01-05
#coding=utf-8 ''' Created on 2015-06-17 @author: xhw ''' import os class CountFile: """統計檔案個數""" def __init__(self): self.root = "D:\ERRORHTML" self.Num = 0 def countfile(self,path): if not os.path.isdir(path): return fileList = os.listdir(path) for fileName in fileList: fileName = os.path.join(path,fileName) if os.path.isdir(fileName): self.countfile(fileName) else: self.Num+=1 def run(self): self.countfile(self.root) print self.Num if __name__ == "__main__": A = CountFile() A.run()