_getdrive

获取当前磁盘驱动器。

重要

此 API 不能用于在 Windows 运行时中执行的应用程序。有关详细信息,请参见 CRT functions not supported with /ZW(CRT 函数不支持使用/ZW)。

int _getdrive( void );

返回值

返回当前值 (默认) 驱动器 (1=A,2=B,等等)。 无错误返回。

要求

例程

必需的标头

_getdrive

<direct.h>

有关兼容性的更多信息,请参见兼容性

示例

// 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 );
}
  

.NET Framework 等效项

System::Environment::CurrentDirectory

请参见

参考

目录控制

_chdrive

_getcwd、_wgetcwd

_getdcwd、_wgetdcwd