David-Sarah Hopwood <david-sa...@jacaranda.org> added the comment: Don't use win32file.GetDiskFreeSpace; the underlying Windows API only supports drives up to 2 GB (http://blogs.msdn.com/b/oldnewthing/archive/2007/11/01/5807020.aspx). Use GetFreeDiskSpaceEx, as the code I linked to does.
I'm not sure it makes sense to provide an exact clone of os.statvfs, since some of the statvfs fields don't have equivalents that are obtainable by any Windows API as far as I know. What <em>would</em> make sense is a cross-platform way to get total disk space, and the space free for root/Administrator and for the current user. This would actually be somewhat easier to use on Unix as well. Anyway, here's some code for Windows that only uses ctypes (whichdir should be Unicode): from ctypes import WINFUNCTYPE, windll, POINTER, byref, c_ulonglong from ctypes.wintypes import BOOL, DWORD, LPCWSTR # <http://msdn.microsoft.com/en-us/library/aa383742%28v=VS.85%29.aspx> PULARGE_INTEGER = POINTER(c_ulonglong) # <http://msdn.microsoft.com/en-us/library/aa364937%28VS.85%29.aspx> GetDiskFreeSpaceExW = WINFUNCTYPE(BOOL, LPCWSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER)( ("GetDiskFreeSpaceExW", windll.kernel32)) # <http://msdn.microsoft.com/en-us/library/ms679360%28v=VS.85%29.aspx> GetLastError = WINFUNCTYPE(DWORD)(("GetLastError", windll.kernel32)) # (This might put up an error dialog unless # SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX) # has been called.) n_free_for_user = c_ulonglong(0) n_total = c_ulonglong(0) n_free = c_ulonglong(0) retval = GetDiskFreeSpaceExW(whichdir, byref(n_free_for_user), byref(n_total), byref(n_free)) if retval == 0: raise OSError("Windows error %d attempting to get disk statistics for %r" % (GetLastError(), whichdir)) free_for_user = n_free_for_user.value total = n_total.value free = n_free.value ---------- versions: +Python 2.7, Python 3.3 -Python 2.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue410547> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com