Export (0) Print
Expand All
div
eof
Expand Minimize

_getdrives

Returns a bitmask that represents the currently available disk drives.

Important note Important

This API cannot be used in applications that execute in the Windows Runtime. For more information, see CRT functions not supported with /ZW.

unsigned long _getdrives( void );

If the function succeeds, the return value is a bitmask that represents the currently available disk drives. Bit position 0 (the least-significant bit) is drive A, bit position 1 is drive B, bit position 2 is drive C, and so on. If the function fails, the return value is zero. To get extended error information, call GetLastError.

Routine

Required header

_getdrives

<direct.h>

For more compatibility information, see Compatibility.

// crt_getdrives.c
// This program retrives and lists out
// all the logical drives that are 
// currently mounted on the machine.

#include <windows.h>
#include <direct.h>
#include <stdio.h>
#include <tchar.h>

TCHAR g_szDrvMsg[] = _T("A:\n");

int main(int argc, char* argv[]) {
   ULONG uDriveMask = _getdrives();

   if (uDriveMask == 0)
   {
      printf( "_getdrives() failed with failure code: %d\n",
              GetLastError());
   }
   else
   {
      printf("The following logical drives are being used:\n");

      while (uDriveMask) {
         if (uDriveMask & 1)
            printf(g_szDrvMsg);

         ++g_szDrvMsg[0];
         uDriveMask >>= 1;
      }
   }
}
The following logical drives are being used:
A:
C:
D:
E:

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

Show:
© 2014 Microsoft