다음을 통해 공유


Directory.GetCurrentDirectory 메서드

응용 프로그램의 현재 작업 디렉터리를 가져옵니다.

네임스페이스: System.IO
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Shared Function GetCurrentDirectory As String
‘사용 방법
Dim returnValue As String

returnValue = Directory.GetCurrentDirectory
public static string GetCurrentDirectory ()
public:
static String^ GetCurrentDirectory ()
public static String GetCurrentDirectory ()
public static function GetCurrentDirectory () : String

반환 값

현재 작업 디렉터리 경로가 들어 있는 문자열입니다.

예외

예외 형식 조건

UnauthorizedAccessException

호출자에게 필요한 권한이 없는 경우

NotSupportedException

운영 체제가 현재 디렉터리 기능이 없는 Windows CE인 경우

이 메서드는 .NET Compact Framework에서 사용할 수 있지만 현재는 지원되지 않습니다.

설명

현재 디렉터리가 프로세스가 시작된 원본 디렉터리와 다릅니다.

다음 표에서는 일반적인 예 또는 관련된 I/O 작업의 예를 보여 줍니다.

수행 작업

참조 항목

텍스트 파일을 만듭니다.

방법: 파일에 텍스트 쓰기

텍스트 파일에 씁니다.

방법: 파일에 텍스트 쓰기

텍스트 파일에서 읽습니다.

방법: 파일의 텍스트 읽기

디렉터리의 파일을 참조하십시오.

Name

디렉터리의 하위 디렉터리를 참조하십시오.

GetDirectories

GetDirectories

디렉터리의 전체 하위 디렉터리에 있는 모든 파일을 참조하십시오.

GetFileSystemInfos

디렉터리의 크기를 찾습니다.

Directory

파일이 있는지 여부를 확인합니다.

Exists

디렉터리가 있는지 여부를 확인합니다.

Exists

Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE 플랫폼 참고: 일부 모바일 장치 운영 체제에는 현재 디렉터리 기능이 없으므로 이 메서드가 지원되지 않습니다.

예제

다음 코드 예제에서는 GetCurrentDirectory 메서드를 사용하는 방법을 보여 줍니다.

Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
        Try
            ' Get the current directory.
            Dim path As String = Directory.GetCurrentDirectory()
            Dim target As String = "c:\temp"
            Console.WriteLine("The current directory is {0}", path)
            If Directory.Exists(target) = False Then
                Directory.CreateDirectory(target)
            End If
            ' Change the current directory.
            Environment.CurrentDirectory = (target)
            If path.Equals(Directory.GetCurrentDirectory()) Then
                Console.WriteLine("You are in the temp directory.")
            Else
                Console.WriteLine("You are not in the temp directory.")
            End If
        Catch e As Exception
            Console.WriteLine("The process failed: {0}", e.ToString())
        End Try
    End Sub
End Class
using System;
using System.IO;

class Test 
{
    public static void Main() 
    {
        try 
        {
            // Get the current directory.
            string path = Directory.GetCurrentDirectory();
            string target = @"c:\temp";
            Console.WriteLine("The current directory is {0}", path);
            if (!Directory.Exists(target)) 
            {
                Directory.CreateDirectory(target);
            }

            // Change the current directory.
            Environment.CurrentDirectory = (target);
            if (path.Equals(Directory.GetCurrentDirectory())) 
            {
                Console.WriteLine("You are in the temp directory.");
            } 
            else 
            {
                Console.WriteLine("You are not in the temp directory.");
            }
        } 
        catch (Exception e) 
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    }
}
using namespace System;
using namespace System::IO;
int main()
{
   try
   {
      
      // Get the current directory.
      String^ path = Directory::GetCurrentDirectory();
      String^ target = "c:\\temp";
      Console::WriteLine( "The current directory is {0}", path );
      if (  !Directory::Exists( target ) )
      {
         Directory::CreateDirectory( target );
      }
      
      // Change the current directory.
      Environment::CurrentDirectory = target;
      if ( path->Equals( Directory::GetCurrentDirectory() ) )
      {
         Console::WriteLine( "You are in the temp directory." );
      }
      else
      {
         Console::WriteLine( "You are not in the temp directory." );
      }
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "The process failed: {0}", e );
   }

}
import System.*;
import System.IO.*;

class Test
{
    public static void main(String[] args)
    {
        try {
            // Get the current directory.
            String path = Directory.GetCurrentDirectory();
            String target = "c:\\temp";

            Console.WriteLine("The current directory is {0}", path);
            if (!(Directory.Exists(target))) {
                Directory.CreateDirectory(target);
            }

            // Change the current directory.
            Environment.set_CurrentDirectory(target);
            if (path.Equals(Directory.GetCurrentDirectory())) {
                Console.WriteLine("You are in the temp directory.");
            }
            else {
                Console.WriteLine("You are not in the temp directory.");
            }
        }
        catch (System.Exception e) {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    } //main
} //Test

.NET Framework 보안

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Directory 클래스
Directory 멤버
System.IO 네임스페이스

기타 리소스

파일 및 스트림 I/O
방법: 파일의 텍스트 읽기
방법: 파일에 텍스트 쓰기