Why does os.path.getsize() return a negative number for a 10gb file?

后端 未结 2 1974
情话喂你
情话喂你 2021-01-12 14:16

I am using the function os.path.getsize() which gives the size of the file in bytes.

As my one file size is 10gb it give me size in negative(bytes).

2条回答
  •  情书的邮戳
    2021-01-12 14:40

    Your Linux kernel obviously has large file support, since ls -l works correctly. Thus, it's your Python installation that is lacking the support. (Are you using your distribution's Python package? What distribution is it?)

    The documentation on POSIX large file support in Python states that Python should typically make use of large file support if it is available on Linux. It also suggests to try and configure Python with the command line

    CFLAGS='-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64' OPT="-g -O2 $CFLAGS" \
        ./configure
    

    And finally, quoting the man page of the stat system call:

    This can occur when an application compiled on a 32-bit platform without -D_FILE_OFFSET_BITS=64 calls stat() on a file whose size exceeds (1<<31)-1 bits.

    (I believe the last word should be "bytes".)

提交回复
热议问题