Skip to content

Commit 83432b9

Browse files
author
Jared Manning
committed
Tidy up comments and syntax, also add main() func.
1 parent 2c58109 commit 83432b9

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

folder_size.py

+23-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
# Script Name : folder_size.py
2-
# Author : Craig Richards
3-
# Created : 19th July 2012
4-
# Last Modified :
5-
# Version : 1.0
1+
# Script Name : folder_size.py
2+
# Author : Craig Richards
3+
# Created : 19th July 2012
4+
# Last Modified : 14 February 2016
5+
# Version : 1.0.1
66

7-
# Modifications :
7+
# Modifications : 1.0.1 - Tidy up comments and syntax, add main() function
88

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

11-
import os # Load the library module
11+
import os # Load the library module
1212

13-
directory = '.' # Set the variable directory to be the current directory
14-
dir_size = 0 # Set the size to 0
15-
for (path, dirs, files) in os.walk(directory): # Walk through all the directories
16-
for file in files: # Get all the files
17-
filename = os.path.join(path, file)
18-
dir_size += os.path.getsize(filename) # Get the sizes, the following lines print the sizes in bytes, Kb, Mb and Gb
19-
print "Folder Size in Bytes = %0.2f Bytes" % (dir_size)
20-
print "Folder Size in Kilobytes = %0.2f KB" % (dir_size/1024.0)
21-
print "Folder Size in Megabytes = %0.2f MB" % (dir_size/1024/1024.0)
22-
print "Folder Size in Gigabytes = %0.2f GB" % (dir_size/1024/1024/1024.0)
13+
directory = '.' # Set the variable directory to be the current directory
14+
dir_size = 0 # Set the size to 0
15+
16+
def main():
17+
for (path, dirs, files) in os.walk(directory): # Walk through all the directories
18+
for file in files: # Get all the files
19+
filename = os.path.join(path, file)
20+
dir_size += os.path.getsize(filename) # Get the sizes, the following lines print the sizes in bytes, Kb, Mb and Gb
21+
print "Folder Size in Bytes = %0.2f Bytes" % (dir_size)
22+
print "Folder Size in Kilobytes = %0.2f KB" % (dir_size/1024.0)
23+
print "Folder Size in Megabytes = %0.2f MB" % (dir_size/1024/1024.0)
24+
print "Folder Size in Gigabytes = %0.2f GB" % (dir_size/1024/1024/1024.0)
25+
26+
if __name__ == '__main__':
27+
main()

0 commit comments

Comments
 (0)