Python - 計算特定目錄底下的檔案以及目錄數量
$ vim countFileandFolder.py
import os
import sys
fileList = []
fileSize = 0
folderCount = 0
rootdir = '/usr/lib'
for root, subFolders, files in os.walk(rootdir):
folderCount += len(subFolders)
for file in files:
f = os.path.join(root,file)
fileSize = fileSize + os.path.getsize(f)
#print(f)
fileList.append(f)
print("Total Size is {0} bytes".format(fileSize))
print(“Total Files “, len(fileList))
print(“Total Folders “, folderCount)
|
留言
張貼留言