March 19, 2024, 03:11:38 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


File size problem

Started by billhsln, February 28, 2019, 02:22:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

I created a program to get the file name, subdirectory and file size of all the movies on a jump drive.  The problem is when the file is over 2.5 meg, it returns a negative value which is not even close to the right size.  I must be doing some thing wrong and I have tried a couple of different things, but nothing seems to give me the right answer.

Billmovie strip.iwb
When all else fails, get a bigger hammer.

fasecero

Can't find anything wrong in your code. I made a quick alternate way to get the file size of large files (tried with a video > 1 GB and it seems to get the rigth value). Maybe it helps

$INCLUDE "windowssdk.inc"

OPENCONSOLE
PRINT
DoSomething()

PRINT
PRINT "Press any key to exit"
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE

SUB DoSomething()
string filename = "C:\\Users\\Gabriel\\Videos\\2019-01-22-2318-42.mp4"
print _GetVideoSize(filename)
ENDSUB

SUB _GetVideoSize(string fullpath), INT64
HANDLE hFile = CreateFile(fullpath, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)

IF hFile <> INVALID_HANDLE_VALUE THEN
LARGE_INTEGER fs

IF GetFileSizeEx(hFile, &fs) THEN
RETURN fs.QuadPart
ENDIF

CloseHandle(hFile)
ENDIF

RETURN 0
ENDSUB

billhsln

Gave your program a try and it worked, but it looks like the problem is not with what it returns, but with doing a STR$(filesize), if I just print it it looks ok, but if I do a STR$(filesize) it prints a negative value.  USING("%q###,###,###",filesize) prints just fine also.  Attaching corrected program.

I know that there is a way to do it without using: GetFileAttributesExA(path+filename,0,wad)

Will need to search for it in my older code.

Thanks,
Bill
When all else fails, get a bigger hammer.

fasecero

February 28, 2019, 08:28:21 PM #3 Last Edit: February 28, 2019, 08:31:19 PM by fasecero
I see, so the problem is to convert INT64 to string. Andy had this same problem a while ago, but finally found a solution. You can check this very large thread for the details

https://www.ionicwind.com/forums/index.php?topic=6059.0

$INCLUDE "windowssdk.inc"

OPENCONSOLE
PRINT
DoSomething()

PRINT
PRINT "Press any key to exit"
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE

SUB DoSomething()
string filename = "C:\\Users\\Gabriel\\Videos\\2019-01-22-2318-42.mp4"

INT64 value = _GetVideoSize(filename)
print value

string strvalue = UINT64ToString(value)
print strvalue
ENDSUB

SUB _GetVideoSize(string fullpath), INT64
HANDLE hFile = CreateFile(fullpath, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)

IF hFile <> INVALID_HANDLE_VALUE THEN
LARGE_INTEGER fs

IF GetFileSizeEx(hFile, &fs) THEN
RETURN fs.QuadPart
ENDIF

CloseHandle(hFile)
ENDIF

RETURN 0
ENDSUB

DECLARE CDECL _ui64toa_sTemplate(UINT64 value, pointer buffer, INT sizeInCharacters, INT radix), INT

SUB UINT64ToString(UINT64 value), string
string buffer = ""

UINT hInst=LoadLibrary("msvcrt.dll")

IF hInst THEN
UINT proc = GetProcAddress(hInst, "_ui64toa_s")

IF proc THEN
value = !<_ui64toa_sTemplate>proc(value, buffer, 200, 10)
ENDIF

FreeLibrary(hInst)
ENDIF

RETURN UCASE$(buffer)
ENDSUB


Andy

February 28, 2019, 11:58:35 PM #4 Last Edit: March 01, 2019, 12:01:55 AM by Andy
Bill,

Fasecero is correct, and helped me with this one.

I made an include file that works with large numbers and you can convert from / to strings / uint64 / int64 ect.

Here is the link (in the Treasure Chest section) to the include file and example program - easy to use:

https://www.ionicwind.com/forums/index.php?topic=6067.0

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

billhsln

Will give the INT64 routines a try.  Strange that STR$ does not work for very large numbers, but at least we know now and can work around it with the utilities that our great users come up with to solve oddities.

Thanks Andy.

Bill
When all else fails, get a bigger hammer.