Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can't make getFileSize work on really big files (20GB)
Message
 
 
À
06/08/2005 19:39:25
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01039116
Message ID:
01039133
Vues:
21
This message has been marked as the solution to the initial question of the thread.
Jeff,

The GetFileSize returns unsigned integer but VFP converts it to a signed integer because it doesn't have unsigned integers. It means that your function will return incorrect resut every time lnSizeLo >= 2^31. The total size of the file doesn't matter.
You've to convert signed integer back to unsigned. Here's one of the way to do that.
lnReturn = m.lnSizeHi * DWORDPLUS + VAL(TRANSFORM(m.lnSizeLo, "@0"))
>*I'm having trouble with the following code to get the size of a really large file.
>*it works with files less than 14GB - actually, I don't know when it starts to break,
>*but certainly, when the file is 24GB it does break.
>
>#define OF_SHARE_DENY_NONE 0x00000040
>#define DWORDPLUS 4294967296 && 0xffffffff + 1
>#define HFILE_ERROR -1
>
>declare integer GetFileSize in Win32API as apiGetFileSize;
> integer hFile,;
> integer @ lpFileSizeHigh
>
>?getFileSize(getfile())
>
>*when the file is 24,117,366,840 bytes my function returns 19,822,399,544
>*when the file is big (above size) the lnSizeLo is negative
>
>*when the file is 14,836,655,764 it returns 14,836,655,764
>*and values below 14,836,655,764 work correctly
>procedure getFileSize(tcFilename as String) as Integer
>
>local lpReOpenBuff, hFile, lnSizeLo, lnSizeHi, lnReturn as Integer
>lnReturn = -1
>
>lpReOpenBuff = replicate(chr(0), 250)
>hFile = apiOpenFile(m.tcFilename, @lpReOpenBuff, OF_SHARE_DENY_NONE)
>
>if m.hFile <> HFILE_ERROR
>   lnSizeHi = 0
>   lnSizeLo = apiGetFileSize(m.hFile, @lnSizeHi)
>   lnReturn = m.lnSizeHi * DWORDPLUS + m.lnSizeLo
>   CloseHandle(m.hFile)
>else
>   lnReturn = -1
>endif
>
>return m.lnReturn
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform