_getdrive

現在のディスク ドライブを取得します。

重要

この API は、Windows ランタイムで実行するアプリケーションでは使用できません。 詳細については、「ユニバーサル Windows プラットフォーム アプリでサポートされていない CRT 関数」を参照してください。

構文

int _getdrive( void );

戻り値

現在の (既定の) ドライブ (1=A、2=B など) を返します。 戻り値 0 は、現在のパスが UNC パスなどの文字ドライブ名で始まらないことを意味します。 または、内部バッファーの割り当てが失敗したことを意味します。 内部割り当てが失敗した場合、errno は ENOMEM に設定されます。

解説

既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT のグローバル状態」を参照してください

必要条件

ルーチンによって返される値 必須ヘッダー
_getdrive <direct.h>

互換性の詳細については、「 Compatibility」を参照してください。

// crt_getdrive.c
// compile with: /c
// Illustrates drive functions including:
//    _getdrive       _chdrive        _getdcwd
//

#include <stdio.h>
#include <direct.h>
#include <stdlib.h>
#include <ctype.h>

int main( void )
{
   int ch, drive, curdrive;
   static char path[_MAX_PATH];

   // Save current drive.
   curdrive = _getdrive();

   printf( "Available drives are:\n" );

   // If we can switch to the drive, it exists.
   for( drive = 1; drive <= 26; drive++ )
   {
      if( !_chdrive( drive ) )
      {
         printf( "%c:", drive + 'A' - 1 );
         if( _getdcwd( drive, path, _MAX_PATH ) != NULL )
            printf( " (Current directory is %s)", path );
         putchar( '\n' );
      }
   }

   // Restore original drive.
   _chdrive( curdrive );
}
Available drives are:
A: (Current directory is A:\)
C: (Current directory is C:\)
E: (Current directory is E:\testdir\bin)
F: (Current directory is F:\)
G: (Current directory is G:\)

関連項目

ディレクトリ コントロール
_chdrive
_getcwd, _wgetcwd
_getdcwd, _wgetdcwd