Skip to content

Commit ebe48ce

Browse files
author
Aaron
committed
Added argument support to folder_size.py
I made it easier to tell which directory by the arguments supplied to calculate folder size. I am trying to learn git and python so any comments is appreciated.
1 parent d9768e2 commit ebe48ce

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

folder_size.py

100644100755
+5-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88

99
# Description : This will scan the current directory and all subdirectories and display the size.
1010

11-
import os # Load the library module
12-
directory = '.' # Set the variable directory to be the current directory
11+
import os, sys # Load the library module and the sys module for the argument vector
12+
try:
13+
directory = sys.argv[1] # Set the variable directory to be the argument supplied by user.
14+
except IndexError:
15+
sys.exit("Must provide an argument.")
1316
dir_size = 0 # Set the size to 0
1417

1518
fsizedicr = {'Bytes': 1, 'Kilobytes': float(1)/1024, 'Megabytes': float(1)/(1024*1024), 'Gigabytes': float(1)/(1024*1024

0 commit comments

Comments
 (0)