fork(1) download
  1. #license: I grant free for all legal and human-rights purposes
  2.  
  3. import os # to work with files
  4. import glob # to search for files
  5. import sys # to support command line/terminal inputs
  6.  
  7. # THIS IS ONLY INTEDED TO DO A SIMPLE TOTAL NUMBER AND TOTAL BYTE COUNT
  8. # OF JUST FILES (NOT DIRECTORIES)
  9. # NOT INTENDED FOR EXACT COMPARING FILE BY FILE!
  10.  
  11. # if there were terminal/command line arguments, assume they are dir paths
  12. if len(sys.argv) > 1:
  13. COMPARE_DIRS = sys.argv[1:] # first argument is this file name, useless for this program
  14. # else, use in-code-defined paths:
  15. else:
  16. print(f"No directories set, using directories defined in this python code. ({sys.argv[0]})")
  17. COMPARE_DIRS = [
  18. "/EXAMPLE/PATH/TO/ONE/DIR",
  19. "/EXAMPLE/PATH/TO/ANOTHER/DIR",
  20. # ...
  21. ]
  22.  
  23. print("### WELCOME TO QUICK COMPARE DIRS ###")
  24. print("Going to compare:")
  25. for i, folder in enumerate(COMPARE_DIRS):
  26. print(f"DIRECTORY {i}: {folder}")
  27.  
  28. print("... comparing ... please wait ...")
  29.  
  30. # get list of all FILES (not directories) in that folder recursively
  31. file_lists = {}
  32. for folder in COMPARE_DIRS:
  33. file_lists[folder] = [f for f in glob.iglob(f"{folder}/**", recursive=True) if os.path.isfile(f)]
  34.  
  35. # count all FILE byte sizes for each list as a manual size addition (NOT SYSTEM TOTAL COUNT!)
  36. file_size_totals = {}
  37. for folder in COMPARE_DIRS:
  38. file_size_totals[folder] = 0
  39. for file in file_lists[folder]:
  40. file_size_totals[folder] += os.path.getsize(file)
  41.  
  42. print("_" * 80) # specific PYTHON feature
  43. print("TOTAL FILE COUNTS: ")
  44. for folder, file_list in file_lists.items():
  45. print(f"{len(file_list)} [{folder}]")
  46.  
  47. print("_" * 80) # specific PYTHON feature
  48. print("TOTAL FILE COUNTS: ")
  49. for folder, file_size_total in file_size_totals.items():
  50. print(f"{file_size_total} [{folder}]")
  51.  
Success #stdin #stdout 0.03s 9568KB
stdin
Standard input is empty
stdout
No directories set, using directories defined in this python code. (./prog)
### WELCOME TO QUICK COMPARE DIRS ###
Going to compare:
DIRECTORY 0: /EXAMPLE/PATH/TO/ONE/DIR
DIRECTORY 1: /EXAMPLE/PATH/TO/ANOTHER/DIR
... comparing ... please wait ...
________________________________________________________________________________
TOTAL FILE COUNTS: 
0 [/EXAMPLE/PATH/TO/ONE/DIR]
0 [/EXAMPLE/PATH/TO/ANOTHER/DIR]
________________________________________________________________________________
TOTAL FILE COUNTS: 
0 [/EXAMPLE/PATH/TO/ONE/DIR]
0 [/EXAMPLE/PATH/TO/ANOTHER/DIR]