abilash
abilash

Reputation: 897

Get available physical drives on local machine

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?

Upvotes: 3

Views: 1356

Answers (1)

Jose Luis
Jose Luis

Reputation: 3361

Try using wmic

wmic diskdrive list

for less info

wmic diskdrive list brief 

Alternatively in c use GetLogicalDrives() first to get all of the drives mapped in the system, and then GetDriveType() to find out which sort of drive each one is. Then sort it out as you want to.

Upvotes: 2

Related Questions