| 1 |
ninoborges |
8 |
import win32file, os
|
| 2 |
|
|
|
| 3 |
|
|
def get_dir_size(path):
|
| 4 |
|
|
total_size = 0
|
| 5 |
|
|
if os.sys.platform == 'win32':
|
| 6 |
|
|
try:
|
| 7 |
|
|
items = win32file.FindFilesW(path + '\\*')
|
| 8 |
|
|
except Exception, err:
|
| 9 |
|
|
return 0
|
| 10 |
|
|
|
| 11 |
|
|
# Add the size or perform recursion on folders.
|
| 12 |
|
|
for item in items:
|
| 13 |
|
|
attr = item[0]
|
| 14 |
|
|
name = item[-2]
|
| 15 |
|
|
size = item[5]
|
| 16 |
|
|
|
| 17 |
|
|
# if (attr & win32con.FILE_ATTRIBUTE_DIRECTORY) and \
|
| 18 |
|
|
# not (attr & win32con.FILE_ATTRIBUTE_SYSTEM): # skip system dirs
|
| 19 |
|
|
# if name not in DIR_EXCLUDES:
|
| 20 |
|
|
total_size += get_dir_size("%s\\%s" % (path, name))
|
| 21 |
|
|
|
| 22 |
|
|
total_size += size
|
| 23 |
|
|
|
| 24 |
|
|
return total_size |