Skip to content

Commit d43cfce

Browse files
committed
Merge pull request geekcomputers#39 from rutvik1010/master
Update folder_size.py
2 parents 65b13b4 + da10311 commit d43cfce

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

folder_size.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
# Script Name : folder_size.py
22
# Author : Craig Richards
33
# Created : 19th July 2012
4-
# Last Modified : 14 February 2016
4+
# Last Modified : 22 February 2016
55
# Version : 1.0.1
66

7-
# Modifications : 1.0.1 - Tidy up comments and syntax, add main() function
7+
# Modifications : Modified the Printing method and added a few comments
88

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

1111
import os # Load the library module
12-
1312
directory = '.' # Set the variable directory to be the current directory
1413
dir_size = 0 # Set the size to 0
1514

16-
for (path, dirs, files) in os.walk(directory): # Walk through all the directories
15+
fsizedicr = {'Bytes': 1, 'Kilobytes': float(1)/1024, 'Megabytes': float(1)/(1024*1024), 'Gigabytes': float(1)/(1024*1024
16+
*
17+
1024)}
18+
19+
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.
1720
for file in files: # Get all the files
18-
filename = os.path.join(path, file)
19-
dir_size += os.path.getsize(filename) # Get the sizes, the following lines print the sizes in bytes, Kb, Mb and Gb
20-
print "Folder Size in Bytes = %0.2f Bytes" % (dir_size)
21-
print "Folder Size in Kilobytes = %0.2f KB" % (dir_size/1024.0)
22-
print "Folder Size in Megabytes = %0.2f MB" % (dir_size/1024/1024.0)
23-
print "Folder Size in Gigabytes = %0.2f GB" % (dir_size/1024/1024/1024.0)
21+
filename = os.path.join(path, file)
22+
dir_size += os.path.getsize(filename) # Add the size of each file in the root dir to get the total size.
23+
24+
for key in fsizedicr: #iterating through the dictionary
25+
print ("Folder Size: " + str(round(fsizedicr[key]*dir_size, 2)) + " " + key) # round function example: round(4.2384, 2) ==> 4.23

osinfo.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
# Script Name : osinfo.py
22
# Author : Craig Richards
33
# Created : 5th April 2012
4-
# Last Modified :
4+
# Last Modified : 22nd February 2016
55
# Version : 1.0
66

7-
# Modifications :
7+
# Modifications : Changed the list to a dictionary. Although the order is lost, the info is with its label.
88

99
# Description : Displays some information about the OS you are running this script on
1010

1111
import platform
1212

13-
profile = [
14-
platform.architecture(),
15-
platform.dist(),
16-
platform.libc_ver(),
17-
platform.mac_ver(),
18-
platform.machine(),
19-
platform.node(),
20-
platform.platform(),
21-
platform.processor(),
22-
platform.python_build(),
23-
platform.python_compiler(),
24-
platform.python_version(),
25-
platform.release(),
26-
platform.system(),
27-
platform.uname(),
28-
platform.version(),
29-
]
30-
for i, item in enumerate(profile, 1):
31-
print '#',i,' ',item
13+
profile = {
14+
'Architecture: ': platform.architecture(),
15+
'Linux Distribution: ': platform.linux_distribution(),
16+
'mac_ver: ': platform.mac_ver(),
17+
'machine: ': platform.machine(),
18+
'node: ': platform.node(),
19+
'platform: ': platform.platform(),
20+
'processor: ': platform.processor(),
21+
'python build: ': platform.python_build(),
22+
'python compiler: ': platform.python_compiler(),
23+
'python version: ': platform.python_version(),
24+
'release: ': platform.release(),
25+
'system: ': platform.system(),
26+
'uname: ': platform.uname(),
27+
'version: ': platform.version(),
28+
}
29+
30+
for key in profile:
31+
print(key + str(profile[key]))

0 commit comments

Comments
 (0)