Share via


_getdrives

更新 : 2007 年 11 月

現在使用できるディスク ドライブを表すビットマスクを返します。

unsigned long _getdrives( void );

戻り値

正常終了した場合は、現在利用できるディスク ドライブを表すビットマスクを返します。ビット位置 0 (最下位ビット) は A ドライブ、ビット位置 1 は B ドライブ、ビット位置 2 は C ドライブ、などのように値を返します。失敗した場合は 0 を返します。拡張エラー情報を取得するには、GetLastError を呼び出します。

必要条件

ルーチン

必須ヘッダー

_getdrives

<direct.h>

互換性の詳細については、「C ランタイム ライブラリ」の「互換性」を参照してください。

使用例

// 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:

同等の .NET Framework 関数

適用できません。標準 C 関数を呼び出すには、PInvoke を使用します。詳細については、「プラットフォーム呼び出しの例」を参照してください。

参照

参照

ディレクトリ制御