From 70271c5f3e097510e15d4c537c3bb824351d2ed2 Mon Sep 17 00:00:00 2001 From: Jared Manning Date: Sat, 13 Feb 2016 23:11:29 -0600 Subject: [PATCH 01/10] Tidy up comments and syntax --- backup_automater_services.py | 39 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/backup_automater_services.py b/backup_automater_services.py index ef974098ddf..da9f0d216f8 100644 --- a/backup_automater_services.py +++ b/backup_automater_services.py @@ -1,30 +1,31 @@ # Script Name : backup_automater_services.py # Author : Craig Richards # Created : 24th October 2012 -# Last Modified : -# Version : 1.0 +# Last Modified : 13th February 2016 +# Version : 1.0.1 -# Modifications : +# Modifications : 1.0.1 - Tidy up the comments and syntax # Description : This will go through and backup all my automator services workflows import shutil # Load the library module import datetime # Load the library module -import os # Load the library module +import os # Load the library module -today=datetime.date.today() # Get Today's date -todaystr=today.isoformat() # Format it so we can use the format to create the directory +today = datetime.date.today() # Get Today's date +todaystr = today.isoformat() # Format it so we can use the format to create the directory -confdir=os.getenv("my_config") # Set the variable by getting the value from the OS setting -dropbox=os.getenv("dropbox") # Set the variable by getting the value from the OS setting -conffile = ('services.conf') # Set the variable as the name of the configuration file -conffilename=os.path.join(confdir, conffile) # Set the variable by combining the path and the file name -sourcedir=os.path.expanduser('~/Library/Services/') # Source directory of where the scripts are located -destdir=os.path.join(dropbox, "My_backups"+"/"+"Automater_services"+todaystr+"/") # Combine several settings to create the destination backup directory - -for file_name in open(conffilename): # Walk through the configuration file - fname = file_name.strip() # Strip out the blank lines from the configuration file - if fname: # For the lines that are not blank - sourcefile=os.path.join(sourcedir, file_name.strip()) # Get the name of the source files to backup - destfile=os.path.join(destdir, file_name.strip()) # Get the name of the destination file names - shutil.copytree(sourcefile, destfile) # Copy the directories +confdir = os.getenv("my_config") # Set the variable by getting the value from the OS setting +dropbox = os.getenv("dropbox") # Set the variable by getting the value from the OS setting +conffile = ('services.conf') # Set the variable as the name of the configuration file +conffilename = os.path.join(confdir, conffile) # Set the variable by combining the path and the file name +sourcedir = os.path.expanduser('~/Library/Services/') # Source directory of where the scripts are located +destdir = os.path.join(dropbox, "My_backups"+"/"+"Automater_services"+todaystr+"/") # Combine several settings to create + + # the destination backup directory +for file_name in open(conffilename): # Walk through the configuration file + fname = file_name.strip() # Strip out the blank lines from the configuration file + if fname: # For the lines that are not blank + sourcefile = os.path.join(sourcedir, file_name.strip()) # Get the name of the source files to backup + destfile = os.path.join(destdir, file_name.strip()) # Get the name of the destination file names + shutil.copytree(sourcefile, destfile) # Copy the directories From 0f47eb3ebcaf090a7a201479120d2a55396e9ddb Mon Sep 17 00:00:00 2001 From: Jared Manning Date: Sat, 13 Feb 2016 23:14:07 -0600 Subject: [PATCH 02/10] Remove unecessary step by combining functions. --- check_file.py | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/check_file.py b/check_file.py index 8df31765f02..290429d7964 100644 --- a/check_file.py +++ b/check_file.py @@ -9,29 +9,28 @@ # Description : Check a file exists and that we can read the file import sys # Import the Modules -import os # Import the Modules - -# Readfile Functions which open the file that is passed to the script - -def readfile(filename): - f = open(filename, 'r') - line = f.read() - print line - -def main(): - if len(sys.argv) == 2: # Check the arguments passed to the script - filename = sys.argv[1] # The filename is the first argument - if not os.path.isfile(filename): # Check the File exists - print '[-] ' + filename + ' does not exist.' - exit(0) - if not os.access(filename, os.R_OK): # Check you can read the file - print '[-] ' + filename + ' access denied' - exit(0) - else: - print '[-] Usage: ' + str(sys.argv[0]) + ' ' # Print usage if not all parameters passed/Checked - exit(0) - print '[+] Reading from : ' + filename # Display Message and read the file contents - readfile(filename) - -if __name__ == '__main__': - main() \ No newline at end of file +import os # Import the Modules + +# Readfile Functions which open the file that is passed to the script + +def readfile(filename): + line = open(filename, 'r').read() + print line + +def main(): + if len(sys.argv) == 2: # Check the arguments passed to the script + filename = sys.argv[1] # The filename is the first argument + if not os.path.isfile(filename): # Check the File exists + print '[-] ' + filename + ' does not exist.' + exit(0) + if not os.access(filename, os.R_OK): # Check you can read the file + print '[-] ' + filename + ' access denied' + exit(0) + else: + print '[-] Usage: ' + str(sys.argv[0]) + ' ' # Print usage if not all parameters passed/Checked + exit(0) + print '[+] Reading from : ' + filename # Display Message and read the file contents + readfile(filename) + +if __name__ == '__main__': + main() From 903d620f4177910c59bec5841300a55d8475cecf Mon Sep 17 00:00:00 2001 From: Jared Manning Date: Sun, 14 Feb 2016 01:39:37 -0600 Subject: [PATCH 03/10] Remove unecessary line and variable Line 21. Combined open() with read() in one line, saving a variable and a line --- check_for_sqlite_files.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/check_for_sqlite_files.py b/check_for_sqlite_files.py index 46bcd37abc1..c5f9a865890 100644 --- a/check_for_sqlite_files.py +++ b/check_for_sqlite_files.py @@ -1,10 +1,10 @@ # Script Name : check_for_sqlite_files.py # Author : Craig Richards # Created : 07 June 2013 -# Last Modified : -# Version : 1.0 +# Last Modified : 14 February 2016 +# Version : 1.0.1 -# Modifications : +# Modifications : 1.0.1 - Remove unecessary line and variable on Line 21 # Description : Scans directories to check if there are any sqlite files in there @@ -18,8 +18,7 @@ def isSQLite3(filename): if getsize(filename) < 100: # SQLite database file header is 100 bytes return False else: - fd = open(filename, 'rb') - Header = fd.read(100) + Header = open(filename, 'rb').read(100) fd.close() if Header[0:16] == 'SQLite format 3\000': From 4540e8acbeba7e55207c5bf5435f18637e1cdb8e Mon Sep 17 00:00:00 2001 From: Jared Manning Date: Sun, 14 Feb 2016 01:46:22 -0600 Subject: [PATCH 04/10] Tidy up comments and syntax --- create_dir_if_not_there.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/create_dir_if_not_there.py b/create_dir_if_not_there.py index 49c5c09cad2..53536d179c5 100644 --- a/create_dir_if_not_there.py +++ b/create_dir_if_not_there.py @@ -1,17 +1,19 @@ -# Script Name : create_dir_if_not_there.py -# Author : Craig Richards -# Created : 09th January 2012 -# Last Modified : 22nd October 2015 -# Version : 1.0 -# Modifications : Added exceptions +# Script Name : create_dir_if_not_there.py +# Author : Craig Richards +# Created : 09th January 2012 +# Last Modified : 22nd October 2015 +# Version : 1.0.1 +# Modifications : Added exceptions +# : 1.0.1 Tidy up comments and syntax +# +# Description : Checks to see if a directory exists in the users home directory, if not then create it -# Description : Checks to see if a directory exists in the users home directory, if not then create it - -import os # Import the OS module +import os # Import the OS module try: - home=os.path.expanduser("~") # Set the variable home by expanding the users set home directory - print home # Print the location - if not os.path.exists(home+'/testdir'): - os.makedirs(home+'/testdir') # If not create the directory, inside their home directory - except Exceptions as e: - print e + home = os.path.expanduser("~") # Set the variable home by expanding the users set home directory + print home # Print the location + + if not os.path.exists(home+'/testdir'): + os.makedirs(home+'/testdir') # If not create the directory, inside their home directory + except Exceptions as e: + print e From aefe4c11c8e7750530c46d4e50ef2f32213f05ff Mon Sep 17 00:00:00 2001 From: Jared Manning Date: Sun, 14 Feb 2016 01:51:06 -0600 Subject: [PATCH 05/10] Fix Spacing --- create_dir_if_not_there.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/create_dir_if_not_there.py b/create_dir_if_not_there.py index 53536d179c5..14de351636a 100644 --- a/create_dir_if_not_there.py +++ b/create_dir_if_not_there.py @@ -1,19 +1,19 @@ -# Script Name : create_dir_if_not_there.py -# Author : Craig Richards -# Created : 09th January 2012 -# Last Modified : 22nd October 2015 -# Version : 1.0.1 -# Modifications : Added exceptions +# Script Name : create_dir_if_not_there.py +# Author : Craig Richards +# Created : 09th January 2012 +# Last Modified : 22nd October 2015 +# Version : 1.0.1 +# Modifications : Added exceptions # : 1.0.1 Tidy up comments and syntax # -# Description : Checks to see if a directory exists in the users home directory, if not then create it +# Description : Checks to see if a directory exists in the users home directory, if not then create it import os # Import the OS module try: - home = os.path.expanduser("~") # Set the variable home by expanding the users set home directory - print home # Print the location + home = os.path.expanduser("~") # Set the variable home by expanding the users set home directory + print home # Print the location if not os.path.exists(home+'/testdir'): - os.makedirs(home+'/testdir') # If not create the directory, inside their home directory + os.makedirs(home+'/testdir') # If not create the directory, inside their home directory except Exceptions as e: print e From 73652662c2f0c60b8ecdfc6b5446d460f58b9b8b Mon Sep 17 00:00:00 2001 From: Jared Manning Date: Sun, 14 Feb 2016 02:02:46 -0600 Subject: [PATCH 06/10] Tidy up comments and syntax, also add main() func. --- daily_checks.py | 78 ++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/daily_checks.py b/daily_checks.py index c9491ca6b2b..275d152cc32 100644 --- a/daily_checks.py +++ b/daily_checks.py @@ -1,41 +1,42 @@ -# Script Name : daily_checks.py -# Author : Craig Richards -# Created : 07th December 2011 -# Last Modified : 01st May 2013 -# Version : 1.4 +# Script Name : daily_checks.py +# Author : Craig Richards +# Created : 07th December 2011 +# Last Modified : 01st May 2013 +# Version : 1.5 +# +# Modifications : 1.1 Removed the static lines for the putty sessions, it now reads a file, loops through and makes the connections. +# : 1.2 Added a variable filename=sys.argv[0] , as when you use __file__ it errors when creating an exe with py2exe. +# : 1.3 Changed the server_list.txt file name and moved the file to the config directory. +# : 1.4 Changed some settings due to getting a new pc +# : 1.5 Tidy comments and syntax +# +# Description : This simple script loads everything I need to carry out the daily checks for our systems. -# Modifications : 1.1 Removed the static lines for the putty sessions, it now reads a file, loops through and makes the connections. -# : 1.2 Added a variable filename=sys.argv[0] , as when you use __file__ it errors when creating an exe with py2exe. -# : 1.3 Changed the server_list.txt file name and moved the file to the config directory. -# : 1.4 Changed some settings due to getting a new pc - -# Description : This simple script loads everything I need to carry out the daily checks for our systems. - -import platform # Load the Library Module -import os # Load the Library Module -import subprocess # Load the Library Module -import sys # Load the Library Module +import platform # Load Modules +import os +import subprocess +import sys from time import strftime # Load just the strftime Module from Time -def clear_screen(): # Function to clear the screen - if os.name == "posix": # Unix/Linux/MacOS/BSD/etc - os.system('clear') # Clear the Screen +def clear_screen(): # Function to clear the screen + if os.name == "posix": # Unix/Linux/MacOS/BSD/etc + os.system('clear') # Clear the Screen elif os.name in ("nt", "dos", "ce"): # DOS/Windows - os.system('CLS') # Clear the Screen + os.system('CLS') # Clear the Screen -def print_docs(): # Function to print the daily checks automatically +def print_docs(): # Function to print the daily checks automatically print "Printing Daily Check Sheets:" # The command below passes the command line string to open word, open the document, print it then close word down subprocess.Popen(["C:\\Program Files (x86)\Microsoft Office\Office14\winword.exe", "P:\\\\Documentation\\Daily Docs\\Back office Daily Checks.doc", "/mFilePrintDefault", "/mFileExit"]).communicate() -def putty_sessions(): # Function to load the putty sessions I need - for server in open(conffilename): # Open the file server_list.txt, loop through reading each line - 1.1 -Changed - 1.3 Changed name to use variable conffilename - subprocess.Popen(('putty -load '+server)) # Open the PuTTY sessions - 1.1 +def putty_sessions(): # Function to load the putty sessions I need + for server in open(conffilename): # Open the file server_list.txt, loop through reading each line - 1.1 -Changed - 1.3 Changed name to use variable conffilename + subprocess.Popen(('putty -load '+server)) # Open the PuTTY sessions - 1.1 def rdp_sessions(): print "Loading RDP Sessions:" - subprocess.Popen("mstsc eclr.rdp") # Open up a terminal session connection and load the euroclear session + subprocess.Popen("mstsc eclr.rdp") # Open up a terminal session connection and load the euroclear session def euroclear_docs(): # The command below opens IE and loads the Euroclear password document @@ -44,15 +45,20 @@ def euroclear_docs(): # End of the functions # Start of the Main Program +def main(): + filename = sys.argv[0] # Create the variable filename + confdir = os.getenv("my_config") # Set the variable confdir from the OS environment variable - 1.3 + conffile = ('daily_checks_servers.conf') # Set the variable conffile - 1.3 + conffilename = os.path.join(confdir, conffile) # Set the variable conffilename by joining confdir and conffile together - 1.3 + clear_screen() # Call the clear screen function + + # The command below prints a little welcome message, as well as the script name, the date and time and where it was run from. + print "Good Morning " + os.getenv('USERNAME') + ", " + filename, "ran at", strftime("%Y-%m-%d %H:%M:%S"), "on",platform.node(), "run from",os.getcwd() + + print_docs() # Call the print_docs function + putty_sessions() # Call the putty_session function + rdp_sessions() # Call the rdp_sessions function + euroclear_docs() # Call the euroclear_docs function -filename=sys.argv[0] # Create the variable filename -confdir = os.getenv("my_config") # Set the variable confdir from the OS environment variable - 1.3 -conffile = ('daily_checks_servers.conf') # Set the variable conffile - 1.3 -conffilename=os.path.join(confdir, conffile) # Set the variable conffilename by joining confdir and conffile together - 1.3 -clear_screen() # Call the clear screen function -# The command below prints a little welcome message, as well as the script name, the date and time and where it was run from. -print "Good Morning " + os.getenv('USERNAME') + ", " + filename, "ran at", strftime("%Y-%m-%d %H:%M:%S"), "on",platform.node(), "run from",os.getcwd() -print_docs() # Call the print_docs function -putty_sessions() # Call the putty_session function -rdp_sessions() # Call the rdp_sessions function -euroclear_docs() # Call the euroclear_docs function \ No newline at end of file +if __name__ == '__main__': + main() From 2c58109b12f65e1e5c9b9cdba7352d00a579f9b3 Mon Sep 17 00:00:00 2001 From: Jared Manning Date: Sun, 14 Feb 2016 02:08:19 -0600 Subject: [PATCH 07/10] Tidy up comments and syntax --- env_check.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/env_check.py b/env_check.py index a85e3dfbd57..406f42e48d9 100644 --- a/env_check.py +++ b/env_check.py @@ -1,24 +1,25 @@ -# Script Name : env_check.py -# Author : Craig Richards -# Created : 14th May 2012 -# Last Modified : -# Version : 1.0 +# Script Name : env_check.py +# Author : Craig Richards +# Created : 14th May 2012 +# Last Modified : 14 February 2016 +# Version : 1.0.1 -# Modifications : +# Modifications : 1.0.1 - Tidy up comments and syntax -# Description : This script will check to see if all of the environment variables I require are set +# Description : This script will check to see if all of the environment variables I require are set import os -confdir = os.getenv("my_config") # Set the variable confdir from the OS environment variable -conffile = 'env_check.conf' # Set the variable conffile -conffilename=os.path.join(confdir, conffile) # Set the variable conffilename by joining confdir and conffile together +confdir = os.getenv("my_config") # Set the variable confdir from the OS environment variable +conffile = 'env_check.conf' # Set the variable conffile +conffilename = os.path.join(confdir, conffile) # Set the variable conffilename by joining confdir and conffile together -for env_check in open(conffilename): # Open the config file and read all the settings - env_check = env_check.strip() # Set the variable as itsself, but strip the extra text out - print '[{}]'.format(env_check) # Format the Output to be in Square Brackets - newenv = os.getenv(env_check) # Set the variable newenv to get the settings from the OS what is currently set for the settings out the configfile - if newenv is None: # If it doesn't exist - print env_check, 'is not set' # Print it is not set - else: # Else if it does exist +for env_check in open(conffilename): # Open the config file and read all the settings + env_check = env_check.strip() # Set the variable as itsself, but strip the extra text out + print '[{}]'.format(env_check) # Format the Output to be in Square Brackets + newenv = os.getenv(env_check) # Set the variable newenv to get the settings from the OS what is currently set for the settings out the configfile + + if newenv is None: # If it doesn't exist + print env_check, 'is not set' # Print it is not set + else: # Else if it does exist print 'Current Setting for {}={}\n'.format(env_check, newenv) # Print out the details From 83432b91232921f76d067cb906779f218debb86d Mon Sep 17 00:00:00 2001 From: Jared Manning Date: Sun, 14 Feb 2016 02:16:07 -0600 Subject: [PATCH 08/10] Tidy up comments and syntax, also add main() func. --- folder_size.py | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/folder_size.py b/folder_size.py index 81d3e5184af..8d22a52e9f5 100644 --- a/folder_size.py +++ b/folder_size.py @@ -1,22 +1,27 @@ -# Script Name : folder_size.py -# Author : Craig Richards -# Created : 19th July 2012 -# Last Modified : -# Version : 1.0 +# Script Name : folder_size.py +# Author : Craig Richards +# Created : 19th July 2012 +# Last Modified : 14 February 2016 +# Version : 1.0.1 -# Modifications : +# Modifications : 1.0.1 - Tidy up comments and syntax, add main() function -# Description : This will scan the current directory and all subdirectories and display the size. +# Description : This will scan the current directory and all subdirectories and display the size. -import os # Load the library module +import os # Load the library module -directory = '.' # Set the variable directory to be the current directory -dir_size = 0 # Set the size to 0 -for (path, dirs, files) in os.walk(directory): # Walk through all the directories - for file in files: # Get all the files - filename = os.path.join(path, file) - dir_size += os.path.getsize(filename) # Get the sizes, the following lines print the sizes in bytes, Kb, Mb and Gb -print "Folder Size in Bytes = %0.2f Bytes" % (dir_size) -print "Folder Size in Kilobytes = %0.2f KB" % (dir_size/1024.0) -print "Folder Size in Megabytes = %0.2f MB" % (dir_size/1024/1024.0) -print "Folder Size in Gigabytes = %0.2f GB" % (dir_size/1024/1024/1024.0) \ No newline at end of file +directory = '.' # Set the variable directory to be the current directory +dir_size = 0 # Set the size to 0 + +def main(): + for (path, dirs, files) in os.walk(directory): # Walk through all the directories + for file in files: # Get all the files + filename = os.path.join(path, file) + dir_size += os.path.getsize(filename) # Get the sizes, the following lines print the sizes in bytes, Kb, Mb and Gb + print "Folder Size in Bytes = %0.2f Bytes" % (dir_size) + print "Folder Size in Kilobytes = %0.2f KB" % (dir_size/1024.0) + print "Folder Size in Megabytes = %0.2f MB" % (dir_size/1024/1024.0) + print "Folder Size in Gigabytes = %0.2f GB" % (dir_size/1024/1024/1024.0) + +if __name__ == '__main__': + main() From 57f7f0a83ee6f7187b506149c51a864f13939c35 Mon Sep 17 00:00:00 2001 From: Jared Manning Date: Sun, 14 Feb 2016 02:20:08 -0600 Subject: [PATCH 09/10] Tidy up comments and syntax --- logs.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/logs.py b/logs.py index 64486c1450f..2321b980cd5 100644 --- a/logs.py +++ b/logs.py @@ -1,21 +1,23 @@ -# Script Name : logs.py -# Author : Craig Richards -# Created : 13th October 2011 -# Last Modified : -# Version : 1.1 -# Modifications : 1.1 - Added the variable zip_program so you can set it for the zip program on whichever OS, so to run on a different OS just change the locations of these two variables. +# Script Name : logs.py +# Author : Craig Richards +# Created : 13th October 2011 +# Last Modified : 14 February 2016 +# Version : 1.2 +# +# Modifications : 1.1 - Added the variable zip_program so you can set it for the zip program on whichever OS, so to run on a different OS just change the locations of these two variables. +# : 1.2 - Tidy up comments and syntax +# +# Description : This script will search for all *.log files in the given directory, zip them using the program you specify and then date stamp them -# Description : This script will search for all *.log files in the given directory, zip them using the program you specify and then date stamp them +import os # Load the Library Module +from time import strftime # Load just the strftime Module from Time -import os # Load the Library Module -from time import strftime # Load just the strftime Module from Time +logsdir="c:\puttylogs" # Set the Variable logsdir +zip_program="zip.exe" # Set the Variable zip_program - 1.1 -logsdir="c:\puttylogs" # Set the Variable logsdir -zip_program="zip.exe" # Set the Variable zip_program - 1.1 - -for files in os.listdir(logsdir): # Find all the files in the directory - if files.endswith(".log"): # Check to ensure the files in the directory end in .log - files1=files+"."+strftime("%Y-%m-%d")+".zip" # Create the Variable files1, this is the files in the directory, then we add a suffix with the date and the zip extension - os.chdir(logsdir) # Change directory to the logsdir - os.system(zip_program + " " + files1 +" "+ files) # Zip the logs into dated zip files for each server. - 1.1 - os.remove(files) # Remove the original log files \ No newline at end of file +for files in os.listdir(logsdir): # Find all the files in the directory + if files.endswith(".log"): # Check to ensure the files in the directory end in .log + files1=files+"."+strftime("%Y-%m-%d")+".zip" # Create the Variable files1, this is the files in the directory, then we add a suffix with the date and the zip extension + os.chdir(logsdir) # Change directory to the logsdir + os.system(zip_program + " " + files1 +" "+ files) # Zip the logs into dated zip files for each server. - 1.1 + os.remove(files) # Remove the original log files From ebaad918295360b14fc838ad1c64f38a20edfe68 Mon Sep 17 00:00:00 2001 From: Jared Manning Date: Sun, 14 Feb 2016 02:27:33 -0600 Subject: [PATCH 10/10] REVERT 83432b9 I'm not sure how to revert this other than like this. My apologies for commit that crap. --- folder_size.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/folder_size.py b/folder_size.py index 8d22a52e9f5..7abe3e19ec3 100644 --- a/folder_size.py +++ b/folder_size.py @@ -13,15 +13,11 @@ directory = '.' # Set the variable directory to be the current directory dir_size = 0 # Set the size to 0 -def main(): - for (path, dirs, files) in os.walk(directory): # Walk through all the directories - for file in files: # Get all the files - filename = os.path.join(path, file) - dir_size += os.path.getsize(filename) # Get the sizes, the following lines print the sizes in bytes, Kb, Mb and Gb - print "Folder Size in Bytes = %0.2f Bytes" % (dir_size) - print "Folder Size in Kilobytes = %0.2f KB" % (dir_size/1024.0) - print "Folder Size in Megabytes = %0.2f MB" % (dir_size/1024/1024.0) - print "Folder Size in Gigabytes = %0.2f GB" % (dir_size/1024/1024/1024.0) - -if __name__ == '__main__': - main() +for (path, dirs, files) in os.walk(directory): # Walk through all the directories + for file in files: # Get all the files + filename = os.path.join(path, file) + dir_size += os.path.getsize(filename) # Get the sizes, the following lines print the sizes in bytes, Kb, Mb and Gb +print "Folder Size in Bytes = %0.2f Bytes" % (dir_size) +print "Folder Size in Kilobytes = %0.2f KB" % (dir_size/1024.0) +print "Folder Size in Megabytes = %0.2f MB" % (dir_size/1024/1024.0) +print "Folder Size in Gigabytes = %0.2f GB" % (dir_size/1024/1024/1024.0)