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.
Bill
movie strip.iwb
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
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
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
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.
:)
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