Last active
August 29, 2015 14:21
-
-
Save fernandojsg/9fcbc50fab7b2f84660d to your computer and use it in GitHub Desktop.
Available and used space in a folder (Python)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def convertSize(size): | |
size_name = ("B","KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") | |
i = int(math.floor(math.log(size,1024))) | |
p = math.pow(1024,i) | |
s = round(size/p,2) | |
if (s > 0): | |
return '%s %s' % (s,size_name[i]) | |
else: | |
return '0B' | |
import os | |
f = os.statvfs("/srv/storage_volumes/data01") | |
total = f.f_frsize*f.f_blocks | |
free = f.f_frsize*f.f_bfree | |
available = f.f_frsize*f.f_bavail | |
used = total - free | |
usedperc = float(used) / total | |
print "Total: " + convertSize(total) | |
print "Available: " + convertSize(available) | |
print "%% Used: %.2f%%" % (usedperc*100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment