Skip to content

Latest commit

 

History

History
90 lines (68 loc) · 2.49 KB

getdrives.md

File metadata and controls

90 lines (68 loc) · 2.49 KB
description title ms.date api_name api_location api_type topic_type f1_keywords helpviewer_keywords ms.assetid
Learn more about: _getdrives
_getdrives
4/2/2020
_getdrives
_o__getdrives
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-filesystem-l1-1-0.dll
DLLExport
apiref
getdrives
_getdrives
_getdrives function
getdrives function
disk drives
869bb51f-4209-4328-846e-3aadebaceb9c

_getdrives

Returns a bitmask that represents the currently available disk drives.

Important

This API cannot be used in applications that execute in the Windows Runtime. For more information, see CRT functions not supported in Universal Windows Platform apps.

Syntax

unsigned long _getdrives( void );

Return value

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

Remarks

By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.

Requirements

Routine Required header
_getdrives <direct.h>

For more compatibility information, see Compatibility.

Example

// crt_getdrives.c
// This program retrieves 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:

See also

Directory control