#!/usr/bin/python # dirsize.py - calculate the total size of files, including hidden ones, # in a directory that is specified on the command line, e.g. # python dirsize.py /home/jdoe/test. # Vesion: 1.0 # Created: 2016-03-28 # Last modified: 2016-03-28 import os, sys # Provide the directory for which you wish to perform the calculation as # an argument on the command line. dirSize = 0 theDir = os.listdir( sys.argv[1] ) for file in theDir: full_path_to_file = sys.argv[1] + "/" + file dirSize = dirSize + os.path.getsize(full_path_to_file) print dirSize