CPP: Windows: Get logical drives
Retrieves a bitmask representing the currently available disk drives.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <Windows.h> | |
int main() | |
{ | |
DWORD drives = GetLogicalDrives(); | |
char start = 'A'; | |
for (int i = 1; i <= 32; i++) { | |
auto x = i - 1; | |
auto driveBit = unsigned(1 << x); | |
if (drives & driveBit) { | |
std::cout << (char)(start + i - 1) << ":" << std::endl; | |
} | |
} | |
return 0; | |
} |
Notes:
- Tested using Visual Studio 2022 C++ Windows Console template
Reference(s):
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getlogicaldrives
No comments:
Post a Comment