话不多说,上代码:
'''
Created on 2018年11月24日@author: wangs
'''
import os
import sysdef traverse(rootdir,tup):
lis = os.listdir(rootdir)
for i in range(0,len(lis)):
if os.path.isdir(os.path.join(rootdir,lis[i])) :
tup = traverse(os.path.join(rootdir,lis[i]),tup)
else:
path = os.path.join(rootdir,lis[i])
print(path)
tup[0] = tup[0] + 1
tup[1] = tup[1] + len(open(path,'rU').readlines())
tup[2] = tup[2] + os.path.getsize(path)
return tup
if __name__ == "__main__":
l = [0,0,0]
rtdir = sys.argv[1]
if rtdir == "--help" or rtdir == "-h":
print("usage:python FILE_NAME ROOT_DIR")
print("example:python .\\0001.py c:\\test")
else:
filenum , linenum , filesize = traverse(rtdir,l)
print(filenum , linenum , filesize)