« Back to profile of boubakr92
-
Python
Folder size calculation in Python on Windows
Folder size calculation in Python on Windows
14:09 Feb 02 2011 | Tags : Windows,http://setcode.net/term,Size,http://setcode.net/term,Folder,http://setcode.net/term,python,
def get_dir_size(path):
total_size = 0
if platform.system() == 'Windows':
try:
items = win32file.FindFilesW(path + '\\*')
except Exception, err:
return 0
# Add the size or perform recursion on folders.
for item in items:
attr = item[0]
name = item[-2]
size = item[5]
if (attr & win32con.FILE_ATTRIBUTE_DIRECTORY) and \
not (attr & win32con.FILE_ATTRIBUTE_SYSTEM): # skip system dirs
if name not in DIR_EXCLUDES:
total_size += get_dir_size("%s\\%s" % (path, name))
total_size += size
return total_size
Add comment
To add a comment, please : Login or Sign up