GETFILESIZE with files > 2GB

Previous topic - Next topic

Kitty Hello

Hi,

GETFILESIZE returns a signed 32 bit integer. That means, file sizes > 2GB will appear negative, and file sizes > 4 GB are cut off.
How should I deal with this? (I have a project where that matters, actually).

1. GETFILESIZE(f$, BYREF nof_gigabytes_to_add% = null)
2. GETFILESIZEEX(f$, BYREF bytes%, BYREF gigabytes%)
3. GETFILESIZE(f$); GETFILESIZEGIGS(f$)

Before you vote, keep in mind that next time someone wants to have FILESEEK and FILEPOS with large files, too...

Slydog

#1
With option 3 (and 2 perhaps), you would need a command maybe 'ISFILESIZEGT2GB()' or something so you know which method to use.
I like option 1,  with an optional BYREF GB counter, for when you may be working with large files.   Its just that if you don't check that gb count, your code may not work for larger files, but hey, it doesn't work now so no problem.

Something like this?:
Code (glbasic) Select
LOCAL fileBytes%
LOCAL fileGBytes%
fileBytes = GETFILESIZE("test.dat", fileGBytes)
DEBUG "File Size: " + (fileGBytes * 1024 * 1024 * 1024) + fileBytes
// Except of course this will STILL overflow, just trying to illustrate its usage


[Edit] Ha, or offer a new 8 byte integer data type!
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

spacefractal

Best is if qword type was supported as glbasic, which is 8 bytes long....
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

bigsofty

Is a 64bit integer type even an option? Well if not I kinda like the 2nd parameters option.

Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Ruidesco

The ideal scenario would be 8-byte integers being automatically used in systems that support them.

Kitty Hello

OK, I reset the poll-counter and added the "8 bit integer" option.

How would you declare such a thing?
LOCAL size as INT64 ?

bigsofty

#6
INT64 sound good to me!  :good:

BTW shouldn't the survey now say "8 byte integers"?
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

MrTAToad

Why not update the current commands to be able to deal with large sizes ?

So change GETFILESIZE to handle 64 (or even 128 :) ) bit integers,  and update the other commands accordingly...

spacefractal

we want 8 bit integers? do you mean 8 bytes integers? hehe.

INT64 sound nice for me.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

hardyx

I vote for using extended functions. This Ex function can handle 8 byte integers. Then the existing code works and when you want to support you use Ex() functions and get the result in a larger type.