forked from KirankumarAmbati/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
folder_size.py
22 lines (18 loc) · 993 Bytes
/
folder_size.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Script Name : folder_size.py
# Author : Craig Richards
# Created : 19th July 2012
# Last Modified :
# Version : 1.0
# Modifications :
# 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
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)