3

I am trying to get all the physical drives available on local machine. I tried to use GetLogicalDrives() but when i'm using this function it gets me also drives that physically not available on the machine, for example floppy drive A. Here is my code:

void FindDrives()
{
    DWORD drives = GetLogicalDrives();
     for (int i=0; i<26; i++)
     {
        if( ( drives & ( 1 << i ) ) )
        {
           wchar_t driveName[] = { L'A' + i, L':', L'\\', L'\0'};
           std::wcout << driveName << std::endl;
        }
     }
}

How can I get only physically available drives?

4

1 回答 1

2

尝试使用wmic

wmic diskdrive list

了解较少的信息

wmic diskdrive list brief 

或者,在 c 中,首先使用 GetLogicalDrives() 来获取系统中映射的所有驱动器,然后使用 GetDriveType() 来找出每个驱动器是哪种类型的驱动器。然后按照你的意愿进行排序。

于 2012-10-23T08:14:36.707 回答