File size error in os.stat with large files.

Tim Peters tim.one at comcast.net
Tue Jul 9 16:11:30 EDT 2002


[Joe Woodward]
> Does anyone know the file size limit that os.stat will handle
> correctly?

It depends on OS, Python version, and whether Python was compiled with
"large file" support.

> I have a 4.2GB file that os.stat is reporting to be 164MB. Smaller
> files seem to work just fine, but I have not played with it to find
> out where the cut-off point is.
>
> I am using Python 2.1 on Windows 2000.

Microsoft's implementations of the standard C functions for doing this stuff
are limited to 32-bit results, and there's no indication of overflow when
they're applied to files that are "too large" for that; information is just
lost.  Python 2.1 uses these MS C functions in 2.1.

Substantial work was done for Python 2.2 to use better large-file functions
on Windows.

C:\Python21>dir \junk\big.file2
07/09/2002  03:57p       5,847,842,817 big.file2

C:\Python21>python
Python 2.1.3 (#35, Apr  8 2002, 17:47:50) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.getsize('/junk/big.file2') # Nonsense result
1552875521
>>>

C:\Python22>python
Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.getsize('/junk/big.file2') # Correct result, as unbounded long
5847842817L
>>>

(Note that getsize() calls a stat()-like routine under the covers; the same
kinds of concerns apply to other calls, like stat() and tell()).  If you
need to do real work with large files on Windows, upgrade to 2.2.1.






More information about the Python-list mailing list