Page 1 of 2

Posted: Tue Oct 08, 2002 2:56 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

I have a massive file (9,833,629,696 bytes) but the FileSize command
reports it as only 1,243,695,104 bytes, due to not handling very big
numbers (yet). Any free way around this until big numbers are
supported? I'd prefer not to use any external DLLs or stuff like that.


PB - Registered PureBasic Coder

Posted: Tue Oct 08, 2002 3:17 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Originally posted by PB

I have a massive file (9,833,629,696 bytes) but the FileSize command
reports it as only 1,243,695,104 bytes, due to not handling very big
numbers (yet). Any free way around this until big numbers are
supported? I'd prefer not to use any external DLLs or stuff like that.
Use the API function GetFileSize_() it returns the size in one low and one high long.. Use like this:

Code: Select all

lSize.l = GetFileSize_(hFile, @hSize.l)
Only remaining problem is that if you want to do arithmetics on these values you have to code your own addition and subtraction routines...

Posted: Tue Oct 08, 2002 3:32 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> Use the API function GetFileSize_() it returns the size in one low
> and one high long.. Use like this: lSize.l = GetFileSize_(hFile, @hSize.l)

lSize.l always returns -1 ? I think I need further help. :)


PB - Registered PureBasic Coder

Posted: Tue Oct 08, 2002 3:45 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

Hi Pb,

This one works fine here.
What it does, is, it calculates sizes in Megabytes and stores the remaining bytes in
SizeRestBytes.

Code: Select all

; Get Size of Files larger that 2 GB
; by Timo Harter

FileName.s = ""  ; name of File you want the size of


hFile.l = CreateFile_(@FileName.s, #GENERIC_READ, #FILE_SHARE_READ, 0, #OPEN_EXISTING, 0, 0)  ; open File
If hFile = 0
  MessageRequester("","Can't open File!",0)  ; File can't be opened
EndIf

lowLONG.l = GetFileSize_(hFile.l, @hiLONG.l)

CloseHandle_(hFile) ; free Handle

SizeRestBytes.l = lowLONG & $FFFFF  ; holds the Number of rest Bytes, after translating to MB

If lowLONG & $80000000
  lowLONG & $7FFFFFFF
  lowLONG>>20
  lowLONG + $800
  hiLONG>20
  hiLONG<<12
EndIf

SizeMB.l = lowLONG+hiLONG   ; Size of File in MB


MessageRequester("FileSize","Size is "+Str(SizeMB)+"MB, and "+Str(SizeRestBytes)+" Bytes",0)
End
Hope this helps...

Timo


--------------------------------
Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs and the universe trying to produce bigger and better idiots.

...So far, the universe is winning.

Posted: Tue Oct 08, 2002 3:50 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Originally posted by PB

> Use the API function GetFileSize_() it returns the size in one low
> and one high long.. Use like this: lSize.l = GetFileSize_(hFile, @hSize.l)

lSize.l always returns -1 ? I think I need further help. :)
Did you provide the function with a proper file handle? Ok a little easier example(with everything in;)

Code: Select all

If ReadFile(0, filename$)
  lSize.l = GetFileSize_(UseFile(0), @hSize.l)
  CloseFile(0)
EndIf

Posted: Tue Oct 08, 2002 4:10 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
Ok a little easier example(with everything in;)

Code: Select all

If ReadFile(0, filename$)
  lSize.l = GetFileSize_(UseFile(0), @hSize.l)
  CloseFile(0)
EndIf
This time it works, but reports the wrong size (it reports what the
regular FileSize command reports, instead of the 9 GB size).

PB - Registered PureBasic Coder

Posted: Tue Oct 08, 2002 4:14 pm
by BackupUser
Restored from previous forum. Originally posted by Franco.

9GB? - it's a movie?
Paul is going where nobody (in PureBasicLand) is gone before...

Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.

Posted: Tue Oct 08, 2002 4:15 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> This one works fine here.

Thanks Timo! Any chance of getting it to show actual byte size? :)

BTW: Pupil, I appreciate your assistance very much, also.


PB - Registered PureBasic Coder

Posted: Tue Oct 08, 2002 4:19 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> 9GB? - it's a movie?

It is, actually. It's a 43 minute uncompressed AVI that I dumped from
VHS to my PC today, of me working in my early days in television. I then
happened to do a FileSize on it and was shocked by the wrong result.

As a side-note, I compressed this AVI to MPG which resulted in a mere
426 MB file -- quite a difference in file size! And it took 9 hours
to compress it.

> Paul is going where nobody (in PureBasicLand) is gone before...

LOL!


PB - Registered PureBasic Coder

Posted: Tue Oct 08, 2002 4:58 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Originally posted by PB
Ok a little easier example(with everything in;)

Code: Select all

If ReadFile(0, filename$)
  lSize.l = GetFileSize_(UseFile(0), @hSize.l)
  CloseFile(0)
EndIf
This time it works, but reports the wrong size (it reports what the
regular FileSize command reports, instead of the 9 GB size).
As it should, the high order long is in the variable hSize, so in other words if you want to show this in a debuger window or requester or whatever you have to code a new str() command that handles doubles or you could show it as a hex number like this:

Code: Select all

temp.s = Hex(lSize)
length = Len(temp)
For i = 1 To 8-length
  temp = "0"+temp
Next
temp = Hex(hSize) + temp

Posted: Tue Oct 08, 2002 5:15 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
you could show it as a hex number like this:

Code: Select all

temp.s = Hex(lSize)
length = Len(temp)
For i = 1 To 8-length
  temp = "0"+temp
Next
temp = Hex(hSize) + temp
I just tried that but the hex number (in "temp") also shows the same
size as the regular FileSize command (sorry!).

PB - Registered PureBasic Coder

Posted: Tue Oct 08, 2002 5:42 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Originally posted by PB
you could show it as a hex number like this:

Code: Select all

temp.s = Hex(lSize)
length = Len(temp)
For i = 1 To 8-length
  temp = "0"+temp
Next
temp = Hex(hSize) + temp
I just tried that but the hex number (in "temp") also shows the same
size as the regular FileSize command (sorry!).
Ok, if you use this with freak's example(because it seemed to work for you), and swap the variables lSize->lowLONG and hSize->hiLONG it should report the right hex value because when debugging the code above it put together a hex double long nicely. I haven't got such big files on my HD so i can't verify the stuff that GetFileSize_() returns.

Posted: Tue Oct 08, 2002 11:20 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

Hi Pb,

I posted a StrDouble() Procedure viewtopic.php?t=2269

You can use it like this (tested with a 4GB file)

Code: Select all

FileName.s = OpenFileRequester("","C:\*.*","*.*|All Files",1)  ; name of File

If OpenFile(0, Filename)
  lowLONG.l = GetFileSize_(UseFile(0), @hiLONG.l)  ; get size
  MessageRequester("Filesize:",StrDouble(lowLONG,hiLONG) + " Bytes",0)  ; display size
  CloseFile(0)
EndIf

End
------

That's it, hope it helps...

Timo

Posted: Wed Oct 09, 2002 4:51 am
by BackupUser
Restored from previous forum. Originally posted by PB.

I had to alter your example slightly to use API calls, as it wasn't
working properly with your StrDouble routine (the file wasn't being
read). Below is what I changed it to.

Also, I note that it's off by 2 bytes on my big AVI... and my AVI is
on an NTFS-formatted drive. See my reply to your StrDouble post...

Code: Select all

filename.s="d:\me.avi"
hFile.l=CreateFile_(@FileName,#GENERIC_READ,#FILE_SHARE_READ,0,#OPEN_EXISTING,0,0)
If hFile
  lowLONG.l=GetFileSize_([url]mailto:hFile,@hiLONG.l[/url])
  CloseHandle_(hFile)
  Debug "File size: "+StrDouble(lowLONG,hiLONG)+" Bytes"
EndIf

PB - Registered PureBasic Coder

Posted: Wed Oct 09, 2002 4:53 am
by BackupUser
Restored from previous forum. Originally posted by scurrier.

try the GetFileSizeEx