File size error in os.stat with large files.

Matt Gerrans matt_gerrans at hp.com
Tue Jul 9 17:27:32 EDT 2002


> You have to compile python with large file support to handle files
> over 2GB.  To test whether you have this enabled:

Do you know why the binaries are not compiled with large file support as
default?   Does it cause other problems or does it slow down os.stat()?

Also, if this is on Windows, short of recompiling Python, you could try
these two things (I don't have time to create a 2+ GB file to test whether
they actually work!  If you are running Windows, you can try it out and let
us know):

from win32com.client import Dispatch
fs = Dispatch('Scripting.FileSystemObject')
fileob = fs.GetFile('c:\\temp\\tkinter.txt' )
print fileob.size

Also, another trick that is even more likely to yield correct results on the
Windows platform (sorry) is to use win32api.FindFiles() (which I think is
implemented with the FindFirstFile() and FindNextFile() APIs to build a
list).   For each matched file, the tuple contains information from
WIN32_FIND_DATA, which includes two 32-bit values: nFileSizeHigh and
nFileSizeLow.  So this should do the trick:

import win32api
fileinfo = win32api.FindFiles( 'c:\\temp\\tkinter.txt' )[0]
size = (long(fileinfo[4]) <<32) + fileinfo[5]

- Matt





More information about the Python-list mailing list