FileSize with massive files
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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
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
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
Only remaining problem is that if you want to do arithmetics on these values you have to code your own addition and subtraction routines...
Use the API function GetFileSize_() it returns the size in one low and one high long.. Use like this: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.
Code: Select all
lSize.l = GetFileSize_(hFile, @hSize.l)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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.
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.
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
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.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
Did you provide the function with a proper file handle? Ok a little easier example(with everything in;)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.![]()
Code: Select all
If ReadFile(0, filename$)
lSize.l = GetFileSize_(UseFile(0), @hSize.l)
CloseFile(0)
EndIf
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
regular FileSize command reports, instead of the 9 GB size).
PB - Registered PureBasic Coder
This time it works, but reports the wrong size (it reports what theOk a little easier example(with everything in;)Code: Select all
If ReadFile(0, filename$) lSize.l = GetFileSize_(UseFile(0), @hSize.l) CloseFile(0) EndIf
regular FileSize command reports, instead of the 9 GB size).
PB - Registered PureBasic Coder
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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
> 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
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
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:Originally posted by PB
This time it works, but reports the wrong size (it reports what theOk a little easier example(with everything in;)Code: Select all
If ReadFile(0, filename$) lSize.l = GetFileSize_(UseFile(0), @hSize.l) CloseFile(0) EndIf
regular FileSize command reports, instead of the 9 GB size).
Code: Select all
temp.s = Hex(lSize)
length = Len(temp)
For i = 1 To 8-length
temp = "0"+temp
Next
temp = Hex(hSize) + temp
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
size as the regular FileSize command (sorry!).
PB - Registered PureBasic Coder
I just tried that but the hex number (in "temp") also shows the sameyou 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
size as the regular FileSize command (sorry!).
PB - Registered PureBasic Coder
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
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.Originally posted by PB
I just tried that but the hex number (in "temp") also shows the sameyou 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
size as the regular FileSize command (sorry!).
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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)
------
That's it, hope it helps...
Timo
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
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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...
PB - Registered PureBasic Coder
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
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm