다음을 통해 공유


_getdrive

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at _getdrive.

Gets the current disk drive.

Important

This API cannot be used in applications that execute in the Windows Runtime. For more information, see CRT functions not supported with /ZW.

Syntax

int _getdrive( void );  

Return Value

Returns the current (default) drive (1=A, 2=B, and so on). There is no error return.

Requirements

Routine Required header
_getdrive <direct.h>

For more compatibility information, see Compatibility.

Example

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

.NET Framework Equivalent

System::Environment::CurrentDirectory

See Also

Directory Control
_chdrive
_getcwd, _wgetcwd
_getdcwd, _wgetdcwd