How to calc easier the "long" filesize from nFileSizeLow andnFileSizeHigh

D

DurumDara

Hi !

I get the file datas with FindFilesW.
I want to calc the filesize from nFileSizeLow and nFileSizeHigh with
easiest as possible, without again calling os.getsize().
How to I do it ? I need good result !

Thanx for help:
dd
 
J

John Machin

Hi !

I get the file datas with FindFilesW.
I want to calc the filesize from nFileSizeLow and nFileSizeHigh with
easiest as possible, without again calling os.getsize().
How to I do it ? I need good result !

Thanx for help:
dd

Hello, *again*, dd

Well I've never heard of this caper before but what I'd do would be a
Google search for e.g. nFileSizeHigh and read the first few articles ...
in particular the first one which warns about bulldust on the MS website :)

HTH,
John

P.S. You have heard of Google, haven't you?
 
J

John Machin

Hi !

I get the file datas with FindFilesW.
I want to calc the filesize from nFileSizeLow and nFileSizeHigh with
easiest as possible, without again calling os.getsize().
How to I do it ? I need good result !

Thanx for help:
dd

Hello, *again*, dd

Well I've never heard of this caper before but what I'd do would be a
Google search for e.g. nFileSizeHigh and read the first few articles ...
in particular the first one which warns about bulldust on the MS website :)

HTH,
John

P.S. You have heard of Google, haven't you?
 
J

John Machin

Shift nFileSizeHigh by 32 and add FileSizeLow.

Uh-ohh. Here we have yet another manifestation of the Y2K bug's little
sibling, the F2G bug.

The above doesn't work for 2GB <= filesize < 4GB, 6GB <= filesize < 8GB,
etc. See below.

Those two items are defined as int (that's *signed* int) -- so if the
punter has a 3 GB file, nFileSizeHigh will be zero and nFileSizeLow will
be -1073741824. *Minus* 1 GB? Hey, d00d, who stole my file-system?

Try this:

fsz = (hi << 32) + lo
if lo < 0:
fsz += 0x100000000

This problem is described in the first article found by googling for
"nFileSizeHigh", as I suggested to the OP. Here is some evidence:

C:\junk>dir gb3.txt
[snip]
31/05/2006 07:59 AM 3,221,225,472 gb3.txt
[snip]
C:\junk>python
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
|>>> import win32file
|>>> d = win32file.FindFilesW(u'gb3.txt')
|>>> d
[(32, <PyTime:30/05/2006 9:43:06 PM>, <PyTime:30/05/2006 9:59:06 PM>,
<PyTime:30/05/2006 9:59:06 PM>, 0, -1073741824, 0, 0, u'gb3.txt', u'')]
|>>> hi, lo = d[0][4:6]
|>>> hi, lo
(0, -1073741824)
|>>> fsz = (hi << 32) + lo
|>>> fsz
-1073741824
|>>> # if lo < 0:
|... fsz += (1 << 32)
|>>>
|>>> fsz
3221225472L
|>>>

Cheers,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top