Skip to content

Instantly share code, notes, and snippets.

@netalkGB
Last active August 27, 2024 16:08
Show Gist options
  • Select an option

  • Save netalkGB/bb22bfc96c8cca48deb9466b3384763e to your computer and use it in GitHub Desktop.

Select an option

Save netalkGB/bb22bfc96c8cca48deb9466b3384763e to your computer and use it in GitHub Desktop.
光学ドライブのドライブレターの一覧を取得 (ドライブにディスクがない場合は除外)
#include <windows.h>
#include <iostream>
#include <string>
int main() {
for (int i = 0; i < 26; ++i) {
TCHAR szDrive[] = { (TCHAR)('A' + i), L':', L'\\', L'\0' };
if (!GetVolumeInformation(szDrive, NULL, NULL, NULL, NULL, NULL, NULL, 0)) continue; // 真が返れば、ディスクはあるようだ
if (GetDriveType(szDrive) != DRIVE_CDROM) continue;
std::cout << (std::string(1, 'A' + i) + ":") << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment