From ebe48cee18d20af0837235723e9b4c3ab0774b60 Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 14 Nov 2016 15:09:09 +1100 Subject: [PATCH] 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. --- folder_size.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) mode change 100644 => 100755 folder_size.py diff --git a/folder_size.py b/folder_size.py old mode 100644 new mode 100755 index f79c9449b96..d89f2232e28 --- a/folder_size.py +++ b/folder_size.py @@ -8,8 +8,11 @@ # Description : This will scan the current directory and all subdirectories and display the size. -import os # Load the library module -directory = '.' # Set the variable directory to be the current directory +import os, sys # Load the library module and the sys module for the argument vector +try: + directory = sys.argv[1] # Set the variable directory to be the argument supplied by user. +except IndexError: + sys.exit("Must provide an argument.") dir_size = 0 # Set the size to 0 fsizedicr = {'Bytes': 1, 'Kilobytes': float(1)/1024, 'Megabytes': float(1)/(1024*1024), 'Gigabytes': float(1)/(1024*1024