Skip to content

Commit d208a4b

Browse files
committed
This will scan the current directory and all subdirectories and display the size.
1 parent 9619c86 commit d208a4b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

folder_size.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Script Name : folder_size.py
2+
# Author : Craig Richards
3+
# Created : 19th July 2012
4+
# Last Modified :
5+
# Version : 1.0
6+
7+
# Modifications :
8+
9+
# Description : This will scan the current directory and all subdirectories and display the size.
10+
11+
import os # Load the library module
12+
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)

0 commit comments

Comments
 (0)