Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update folder_size.py #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions folder_size.py
Original file line number Diff line number Diff line change
@@ -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
42 changes: 21 additions & 21 deletions osinfo.py
Original file line number Diff line number Diff line change
@@ -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]))