Pozdrav, kako najlakse procitati informacije o disku u c++
(znaci izlistavanje svih particija, velicina, tip, slobodan prostor)?
Dali baš treba WIN32 API koristiti za to ili? :/
Pozdrav, kako najlakse procitati informacije o disku u c++
(znaci izlistavanje svih particija, velicina, tip, slobodan prostor)?
Dali baš treba WIN32 API koristiti za to ili? :/
U oba slučaja dodati:
#include <IOUtils.hpp>
Za izlistavanje particija i provjeru njihovog tipa:
System::DynamicArray<System::UnicodeString>lstDrives =
TDirectory::GetLogicalDrives();
for (int i = 0; i < lstDrives.Length; i++) {
AnsiString strDrive = lstDrives[i];
UINT drvType = GetDriveType(strDrive.c_str());
if (drvType == DRIVE_NO_ROOT_DIR)
ShowMessage(L"Drive: " + lstDrives[i] +
L"\n" L"The root path is invalid; for example, "
L"there is no volume is mounted at the path");
else if (drvType == DRIVE_REMOVABLE)
ShowMessage(L"Drive: " + lstDrives[i] +
"\n" L"The drive has removable media (floppy drive or flash card reader)"
);
else if (drvType == DRIVE_FIXED)
ShowMessage(L"Drive: " + lstDrives[i] +
"\n" L"The drive has fixed media (drive, flash drive, or thumb drive)"
);
else if (drvType == DRIVE_REMOTE)
ShowMessage(L"Drive: " + lstDrives[i] +
"\n" L"The drive is a remote (network) drive");
else if (drvType == DRIVE_CDROM)
ShowMessage(L"Drive: " + lstDrives[i] +
"\n" L"The drive is a CD-ROM drive or a DVD drive");
else if (drvType == DRIVE_RAMDISK)
ShowMessage(L"Drive: " + lstDrives[i] +
"\n" L"The drive is a RAM disk");
else // if( drvType == DRIVE_UNKNOWN )
ShowMessage(L"The drive type cannot be determined");
}
Za provjeru veličine diska, slobodnog prostora (postavi tri labele na formu):
DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters;
__int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;
::GetDiskFreeSpaceEx("C:\\", (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes);
Label1->Caption = "Avaliable disk space (for this user): " + AnsiString(i64FreeBytesToCaller/1024/1024 ) + " MB";
Label2->Caption = "Total disk space: " + AnsiString(i64TotalBytes /1024/1024 ) + " MB";
Label3->Caption = "Free disk space: " + AnsiString(i64FreeBytes /1024/1024) + " MB";