Environment.CurrentDirectory 속성

정의

현재 작업 디렉터리의 정규화된 경로를 가져오거나 설정합니다.

public:
 static property System::String ^ CurrentDirectory { System::String ^ get(); void set(System::String ^ value); };
public static string CurrentDirectory { get; set; }
static member CurrentDirectory : string with get, set
Public Shared Property CurrentDirectory As String

속성 값

디렉터리 경로입니다.

예외

빈 문자열("")로 설정하려고 했습니다.

null로 설정하려고 한 경우

I/O 오류가 발생했습니다.

찾을 수 없는 로컬 경로를 설정하려고 했습니다.

호출자에게 해당 권한이 없습니다.

예제

다음 예제에서는 설정 하는 속성입니다 CurrentDirectory .

using namespace System;
using namespace System::IO;

void main()
{
      if (Environment::OSVersion->Platform == PlatformID::Win32NT)
      {
            // Change the directory to %WINDIR%
            Environment::CurrentDirectory = Environment::GetEnvironmentVariable( "windir" );
            DirectoryInfo^ info = gcnew DirectoryInfo( "." );

            Console::WriteLine("Directory Info:   {0}", info->FullName);
      }
      else
      {
            Console::WriteLine("This example runs on Windows only.");
      }
}
// The example displays output like the following on a .NET implementation running on Windows:
//        Directory Info:   C:\windows
// The example displays the following output on a .NET implementation on Unix-based systems:
//        This example runs on Windows only.
using System;
using System.IO;

public class Example
{
   public static void Main()
   {
      if (Environment.OSVersion.Platform == PlatformID.Win32NT)
      {
         // Change the directory to %WINDIR%
         Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir");
         DirectoryInfo info = new DirectoryInfo(".");

         Console.WriteLine("Directory Info:   " + info.FullName);
      }
      else
      {
         Console.WriteLine("This example runs on Windows only.");
      }
   }
}
// The example displays output like the following on a .NET implementation running on Windows:
//        Directory Info:   C:\windows
// The example displays the following output on a .NET implementation on Unix-based systems:
//        This example runs on Windows only.
open System
open System.IO

if Environment.OSVersion.Platform = PlatformID.Win32NT then
    // Change the directory to %WINDIR%
    Environment.CurrentDirectory <- Environment.GetEnvironmentVariable "windir"
    
    let info = DirectoryInfo "."

    printfn $"Directory Info:   {info.FullName}"
else
    printfn "This example runs on Windows only."
// The example displays output like the following on a .NET implementation running on Windows:
//        Directory Info:   C:\windows
// The example displays the following output on a .NET implementation on Unix-based systems:
//        This example runs on Windows only.
Imports System.IO

Module Example
   Public Sub Main()
        If Environment.OSVersion.Platform = PlatformID.Win32NT Then
            ' Change the directory to %WINDIR%
            Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir")
            Dim info As New DirectoryInfo(".")
            Console.WriteLine("Directory Info:   " + info.FullName)
         Else
            Console.WriteLine("This example runs on Windows only.")
         End If
   End Sub
End Module
' The example displays output like the following on a .NET implementation running on Windows:
'        Directory Info:   C:\windows
' The example displays the following output on a .NET implementation on Unix-based systems:
'        This example runs on Windows only.

설명

정의에 따라 이 프로세스가 로컬 또는 네트워크 드라이브의 루트 디렉터리에서 시작되는 경우 이 속성의 값은 드라이브 이름 뒤에 후행 슬래시(예: "C:\")입니다. 이 프로세스가 하위 디렉터리에서 시작되는 경우 이 속성의 값은 후행 슬래시(예: "C:\mySubDirectory")가 없는 드라이브 및 하위 디렉터리 경로입니다.

적용 대상