-1

I have a question on window folder property. When I'm checking property it's shows two size that is size and disk on size. So whenever I'm using qfileinfo it's show only size of folder. But i need "Size on disk". So what's is the method to get size on disk. And please explain that why is happening.

Help me for this.

Thanks in advance.

I want to check size on disk by qt C++ language

  • As workaround, you can use [GetDiskFreeSpaceEx](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdiskfreespaceexa), the api can get the total number of free bytes on a disk that are available to the user. – Joel Dec 14 '22 at 02:12
  • 1
    The reason there are two numbers is simple. Files on disk are forced to be a multiple of some allocation size, such as 512 bytes. Even if the file is only 10 bytes long, it will use 512 bytes of the disk simply because that's the way the file system works. It's not easy to get that information in an OS-independent manner as Qt needs it to be. – Mark Ransom Dec 14 '22 at 03:24

1 Answers1

0

I doubt QT had a direct function to achieve the size on disk. May be you can try like something below using windows API (as you mentioned windows).

Include fileapi.h, also below code not tested. Ensure compiled.

#include <Fileapi.h>

//GET THE FULL FILE NAME
QString filePath = qFileInfo->filePath();

//CONVERT THE FILE NAME TO LPCWSTR
LPCWSTR lpcwstrFilePath = (const wchar_t*) filePath.utf16();

//GET THE SIZE ON DISK
unsigned _int64 sizeOnDisk = GetCompressedFileSizeW(lpcwstrFilePath);

https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getcompressedfilesizew

Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34