Export (0) Print
Expand All

_getdrives

Returns a bitmask representing the currently available disk drives.

unsigned long _getdrives();

Return Value

If the function succeeds, the return value is a bitmask representing 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.

Requirements

Routine Required header Compatibility
_getdrives <direct.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example

// crt_getdrives.c
#include <windows.h>
#include <direct.h>
#include <stdio.h>
#include <tchar.h>

TCHAR g_szDrvMsg[] = _T("\tA:\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[1];
         uDriveMask >>= 1;
      }
   }
}

Sample Output

The following logical drives are being used:
        A:
        C:
        D:
        E:

See Also

Directory Control Routines | Run-Time Routines and .NET Framework Equivalents

Show:
© 2014 Microsoft