File sizes from MSWin...

David Bolen db3l at fitlinxx.com
Fri Apr 26 15:08:18 EDT 2002


Christopher Encapera <ChrisE at lantech.com> writes:

> When I try:
> 
> >>> os.path.getsize('x:\\exchsrvr\\mdbdata\\PRIV.EDB')
> 1475354624
> >>> 
> 
> (1,475,354,624 bytes)
> The actual size is 14,360,256,512 bytes.  When I try:

I expect you're seeing truncation due to the use of 32-bit values for
the size.  Until Python 2.2, the Windows version didn't include large
file support (not sure if you could manually build it that way or not,
but it didn't come pre-built with it).

> >>> import win32file
> >>> a = win32file.GetFileSize('X:\\exchsrvr\\mdbdata\\PRIV.EDB')
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> TypeError: The object is not a PyHANDLE object

The GetFileSize() function can only be used on an open file handle
(not on a filename).  So you could do:

    source = win32file.CreateFile('X:\\exchsrvr\\mdbdata\\PRIV.EDB'),
                                  win32file.GENERIC_READ,
                                  win32file.FILE_SHARE_READ,None,
                                  win32file.OPEN_EXISTING,0,None)
    size = win32file.GetFileSize(source)
    source.Close()

The other option (closer to what os.path.getsize is doing) would be to
do a directory listing with Win32 calls (FindFirstFile - implemented
within win32api.FindFiles) and use the size from the directory entry
which can be 64-bit.

> This is the MS Exchange private information store, and ours is large (13.3
> G).  Any suggestions on how to get an accurate size?  I have ActiveState
> ActivePython 2.1 installed, and X: is a mapped drive to a WinNT machine from
> a Win2k workstation...
> Thanks in advance!

If you upgrade to 2.2 you should be fine.  That includes large file
(64-bit) support under Windows by default, and the os.path.getsize()
call will return a long integer rather than an integer.  The bonus is
that it's then also portable across systems rather than limited to
Windows.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list