I'm trying to calculate a file's size on disk
(not simply the file size), but it doesn't seem to be working accurately. I initially used a method described on the MSDN forums, which involved using GetDiskFreeSpace to return cluster size. I took the uint value of lpBytesPerSector and performed the following calculation:
uint TotalSize = lpBytesPerSector * ((FileLength + lpBytesPerSector - 1) / lpBytesPerSector)
The result is inaccurate, however. I run this calculation on all of the files in a particular folder, and it returns a value of 3,491,840 bytes. Windows Explorer indicates that the folder's size on disk is 21,057,536 bytes.
Is there a better or more accurate way to perform this calculation?