| title |
_getdrives | Microsoft Docs |
| ms.custom |
|
| ms.date |
11/04/2016 |
| ms.reviewer |
|
| ms.suite |
|
| ms.technology |
|
| ms.tgt_pltfrm |
|
| ms.topic |
article |
| apiname |
|
| apilocation |
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 |
|
| apitype |
DLLExport |
| f1_keywords |
|
| dev_langs |
|
| helpviewer_keywords |
_getdrives function |
getdrives function |
disk drives |
|
| ms.assetid |
869bb51f-4209-4328-846e-3aadebaceb9c |
| caps.latest.revision |
18 |
| author |
corob-msft |
| ms.author |
corob |
| manager |
ghogen |
| translation.priority.ht |
cs-cz |
de-de |
es-es |
fr-fr |
it-it |
ja-jp |
ko-kr |
pl-pl |
pt-br |
ru-ru |
tr-tr |
zh-cn |
zh-tw |
|
Returns a bitmask that represents the currently available disk drives.
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:
Directory Control