We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 9f201e0 + 9cda0ed commit 6c42bdaCopy full SHA for 6c42bda
folder_size.py
@@ -21,5 +21,9 @@
21
filename = os.path.join(path, file)
22
dir_size += os.path.getsize(filename) # Add the size of each file in the root dir to get the total size.
23
24
-for key in fsizedicr: #iterating through the dictionary
25
- print ("Folder Size: " + str(round(fsizedicr[key]*dir_size, 2)) + " " + key) # round function example: round(4.2384, 2) ==> 4.23
+fsizeList = [str(round(fsizedicr[key]*dir_size, 2)) + " " + key for key in fsizedicr] # List of units
+
26
+if dir_size == 0: print ("File Empty") # Sanity check to eliminate corner-case of empty file.
27
+else:
28
+ for units in sorted(fsizeList)[::-1]: # Reverse sort list of units so smallest magnitude units print first.
29
+ print ("Folder Size: " + units)
0 commit comments