Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Tidy up comments and syntax, also add main() func.
  • Loading branch information
Jared Manning committed Feb 14, 2016
commit 83432b91232921f76d067cb906779f218debb86d
41 changes: 23 additions & 18 deletions folder_size.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
# Script Name : folder_size.py
# Author : Craig Richards
# Created : 19th July 2012
# Last Modified :
# Version : 1.0
# Script Name : folder_size.py
# Author : Craig Richards
# Created : 19th July 2012
# Last Modified : 14 February 2016
# Version : 1.0.1

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

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

import os # Load the library module
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)
directory = '.' # Set the variable directory to be the current directory
dir_size = 0 # Set the size to 0

def main():
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)

if __name__ == '__main__':
main()