Mohammad Azhar Khan aka MAK

Software Engineer. Loves Python. Knows Python, Flask, Django, Node.js, serverless,AWS lambda and many more.

 Get Directory Size using Python

29 Jun 2016 » python, python3

Well, I always wondered the scope of Python and Finally Realised it is limitless. The following script named “” is written in python 3.x


The following python script has following properties

  • requires python 3.x to run
  • Tell the size of directory in which it is placed
  • Tested on Unix(MacOs and Ubuntu)
  • But should also work on windows *Try, test, run and then write your own And I forgot something, Hello everyone :-)
import os
totalSize = 0
for filename in os.listdir(os.getcwd()):
    if not os.path.isfile(os.path.join(os.getcwd(),filename)):
    totalSize = totalSize + os.path.getsize(os.path.join(os.getcwd(),filename))
print("Total Size of current working directory is {0:.2f} Kilo bytes".format(totalSize/1024))