Skip to content

Commit 6c42bda

Browse files
Merge pull request geekcomputers#77 from wbmonroe/patch-1
Update to folder_size.py
2 parents 9f201e0 + 9cda0ed commit 6c42bda

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

folder_size.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@
2121
filename = os.path.join(path, file)
2222
dir_size += os.path.getsize(filename) # Add the size of each file in the root dir to get the total size.
2323

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
24+
fsizeList = [str(round(fsizedicr[key]*dir_size, 2)) + " " + key for key in fsizedicr] # List of units
25+
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

Comments
 (0)