This may help:
import os
import os.path
def getSize(path):
totalsize,filecnt = 0,0
for root, dirs, files in os.walk(path):
for file in files:
tgt=os.path.join(root,file)
if os.path.exists(tgt):
size = os.stat(tgt).st_size
totalsize = totalsize + size
filecnt+=1
return totalsize,filecnt
print '{:,} bytes in {:,} files'.format(*getSize('/Users/droid'))
Prints:
110,058,100,086 bytes in 449,723 files
Or, if it is a permission error, use this:
try:
size = os.stat(tgt).st_size
totalsize = totalsize + size
filecnt+=1
except (#Permission Error type...):
continue