I want to enumerate all available drive letters (which aren\'t already taken) in Windows using VC++.
How can I do this?
std::vector getListOfDrives() {
std::vector arrayOfDrives;
char* szDrives = new char[MAX_PATH]();
if (GetLogicalDriveStringsA(MAX_PATH, szDrives));
for (int i = 0; i < 100; i += 4)
if (szDrives[i] != (char)0)
arrayOfDrives.push_back(std::string{szDrives[i],szDrives[i+1],szDrives[i+2]});
delete[] szDrives;
return arrayOfDrives;
}
returns a vector of drives e.g. C:\D:\E:\F:\
std::vector drives = getListOfDrives();
for (std::string currentDrive : drives) {
std::cout << currentDrive << std::endl;
}
enumerateing over them