You need a hidden stat result element called st_blocks .
>>> s = os.stat('some_file') >>> s posix.stat_result(st_mode=33261, st_ino=12583347, st_dev=234881026, st_nlink=1, st_uid=1000, st_gid=20, st_size=9889973, st_atime=1301371810, st_mtime=847731600, st_ctime=1301371422) >>> s.st_size / 1e6
This file has about 10 MB in the fork resource, which appears as a result of stat , but in the "hidden" attribute. (Bonus points for anyone who knows exactly what file it is.) Note that the man 2 stat states that the st_blocks attribute always measures increments of 512 bytes.
Note. st_size measures the number of bytes of data, but st_blocks measures the size of the disk, including overhead from partially used blocks. In this way,
>>> open('file.txt', 'w').write('Hello, world!') 13 >>> s = os.stat('file.txt') >>> s.st_size 13 >>> s.st_blocks * 512 4096
Now, if you do "Get Information" in Finder, you will see that the file has:
Size: 4 KB on disk (13 bytes)
source share