$ 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) 參考來源 : recursive list files in a dir using Python
留言
張貼留言