×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Python
Posted by: Roman Ignatov
Added: Nov 24, 2016 4:29 PM
Views: 12
Tags: sysadmin
  1. import os
  2. import sys
  3.  
  4. #================================================================================
  5. # List of all the files, total count of files and folders & Total size of files.
  6. #================================================================================
  7.  
  8. fileList = []
  9. fileSize = 0
  10. folderCount = 0
  11. rootdir = sys.argv[1]
  12.  
  13. for root, subFolders, files in os.walk(rootdir):
  14.     folderCount += len(subFolders)
  15.     for file in files:
  16.         f = os.path.join(root,file)
  17.         fileSize = fileSize + os.path.getsize(f)
  18.         print(f)
  19.         fileList.append(f)
  20.  
  21. print("Total Size is {0} bytes".format(fileSize))
  22. print("Total Files ", len(fileList))
  23. print("Total Folders ", folderCount)