Windows property "SIZE ON DISK" How to get this size by qt C++

87 Views Asked by At

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

1

There are 1 best solutions below

0
Pavan Chandaka On

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