_getdrive

현재 디스크 드라이브를 가져옵니다.

Important

이 API는 Windows 런타임에서 실행되는 애플리케이션에서 사용할 수 없습니다. 자세한 내용은 유니버설 Windows 플랫폼 앱에서 지원되지 않는 CRT 함수를 참조하세요.

구문

int _getdrive( void );

반환 값

현재(기본) 드라이브(1=A, 2=B 등)를 반환합니다. 반환 값이 0이면 현재 경로가 UNC 경로와 같은 문자 드라이브 이름으로 시작되지 않습니다. 또는 내부 버퍼 할당이 실패했음을 의미합니다. 내부 할당이 실패하면 ENOMEM으로 설정됩니다 errno .

설명

기본적으로 이 함수의 전역 상태는 애플리케이션으로 범위가 지정됩니다. 이 동작을 변경하려면 CRT의 전역 상태를 참조하세요.

요구 사항

루틴에서 반환된 값 필수 헤더
_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 );
}
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