I am programming with C++ in visual studio 2010 and I was wondering if there is an easy way to get the remaining space of a hard drive in MB. I am making a program that records images and I want to be able to see the remaining space. I noticed that visual basic has the following:
Dim cdrive As System.IO.DriveInfo
cdrive = My.Computer.FileSystem.GetDriveInfo("C:\")
MsgBox(cdrive.TotalSize)
Is there anything like this in C++? Thanks
Edit 1: Thanks for the responses guys, I have just finished work so I'll have a look at your suggestions tomorrow
GetFreeDiskspaceEx is what you want to call.
Sample code here .
There are 2 functions to do that
GetDiskFreeSpace
GetDiskFreeSpaceEx
CString clString;
ULARGE_INTEGER ulFree;
ULARGE_INTEGER ulTotal;
GetDiskFreeSpaceEx ("c:\\", &ulFree, &ulTotal, NULL);
clString.Format ("%f", (double)(signed __int64)(ulFree.QuadPart) / (1024 * 1024 * 1024));
clString = clString.Mid (0, clString.Find ('.') + 2) + " Gb";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.