def diskusage(human_readable=False, path=None):
 if (not path):
  path = 'c:/'
 (_, total, free) = (ctypes.c_ulonglong(), ctypes.c_ulonglong(), ctypes.c_longlong())
 if ((sys.version_info >= (3,)) or isinstance(path, six.text_type)):
  fun = ctypes.windll.kernel32.GetDiskFreeSpaceExw
 else:
  fun = ctypes.windll.kernel32.GetDiskFreeSpaceExA
 ret = fun(path, ctypes.byref(_), ctypes.byref(total), ctypes.byref(free))
 if (ret == 0):
  raise ctypes.WinError()
 used = (total.value - free.value)
 total_val = total.value
 used_val = used
 free_val = free.value
 if human_readable:
  total_val = _byte_calc(total_val)
  used_val = _byte_calc(used_val)
  free_val = _byte_calc(free_val)
 return {'total': total_val, 'used': used_val, 'free': free_val}

def diskusage ( human_readable = False , path = None ) : if ( not path ) : path = 'c:/' ( _ , total , free ) = ( ctypes . c_ulonglong ( ) , ctypes . c_ulonglong ( ) , ctypes . c_longlong ( ) ) if ( ( sys . version_info >= ( 3 , ) ) or isinstance ( path , six . text_type ) ) : fun = ctypes . windll . kernel32 . GetDiskFreeSpaceExw else : fun = ctypes . windll . kernel32 . GetDiskFreeSpaceExA ret = fun ( path , ctypes . byref ( _ ) , ctypes . byref ( total ) , ctypes . byref ( free ) ) if ( ret == 0 ) : raise ctypes . WinError ( ) used = ( total . value - free . value ) total_val = total . value used_val = used free_val = free . value if human_readable : total_val = _byte_calc ( total_val ) used_val = _byte_calc ( used_val ) free_val = _byte_calc ( free_val ) return { 'total' : total_val , 'used' : used_val , 'free' : free_val }
recursively calculate disk usage of path and return it in bytes cli example: .