diff --git a/folder_size.py b/folder_size.py index 7abe3e19ec3..8f63213cea5 100644 --- a/folder_size.py +++ b/folder_size.py @@ -1,23 +1,25 @@ # Script Name : folder_size.py # Author : Craig Richards # Created : 19th July 2012 -# Last Modified : 14 February 2016 +# Last Modified : 22 February 2016 # Version : 1.0.1 -# Modifications : 1.0.1 - Tidy up comments and syntax, add main() function +# Modifications : Modified the Printing method and added a few comments # 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 dir_size = 0 # Set the size to 0 -for (path, dirs, files) in os.walk(directory): # Walk through all the directories +fsizedicr = {'Bytes': 1, 'Kilobytes': float(1)/1024, 'Megabytes': float(1)/(1024*1024), 'Gigabytes': float(1)/(1024*1024 + * + 1024)} + +for (path, dirs, files) in os.walk(directory): # Walk through all the directories. For each iteration, os.walk returns the folders, subfolders and files in the dir. 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) + filename = os.path.join(path, file) + dir_size += os.path.getsize(filename) # Add the size of each file in the root dir to get the total size. + +for key in fsizedicr: #iterating through the dictionary + print ("Folder Size: " + str(round(fsizedicr[key]*dir_size, 2)) + " " + key) # round function example: round(4.2384, 2) ==> 4.23 diff --git a/osinfo.py b/osinfo.py index a189770012d..fc8a8a18d4a 100644 --- a/osinfo.py +++ b/osinfo.py @@ -1,31 +1,31 @@ # Script Name : osinfo.py # Author : Craig Richards # Created : 5th April 2012 -# Last Modified : +# Last Modified : 22nd February 2016 # Version : 1.0 -# Modifications : +# Modifications : Changed the list to a dictionary. Although the order is lost, the info is with its label. # Description : Displays some information about the OS you are running this script on import platform -profile = [ -platform.architecture(), -platform.dist(), -platform.libc_ver(), -platform.mac_ver(), -platform.machine(), -platform.node(), -platform.platform(), -platform.processor(), -platform.python_build(), -platform.python_compiler(), -platform.python_version(), -platform.release(), -platform.system(), -platform.uname(), -platform.version(), -] -for i, item in enumerate(profile, 1): - print '#',i,' ',item +profile = { +'Architecture: ': platform.architecture(), +'Linux Distribution: ': platform.linux_distribution(), +'mac_ver: ': platform.mac_ver(), +'machine: ': platform.machine(), +'node: ': platform.node(), +'platform: ': platform.platform(), +'processor: ': platform.processor(), +'python build: ': platform.python_build(), +'python compiler: ': platform.python_compiler(), +'python version: ': platform.python_version(), +'release: ': platform.release(), +'system: ': platform.system(), +'uname: ': platform.uname(), +'version: ': platform.version(), +} + +for key in profile: + print(key + str(profile[key]))