Monday, February 02, 2009

Helpful Python Methods

import os

def getFreeSpace(path):
  # Gets the number of free bytes in the given path
  st = os.statvfs(path)
  return st.f_bsize * st.f_bavail

def getFileSize(filepath):
  # Gets the size of the file in bytes
  try:
    st = os.stat(filepath)
except IOError:
print "Failed to get size of", filepath
else:
return st[6]