Nyelv

Environment.CurrentDirectory Tulajdonság

Definíció

Lekéri vagy beállítja az aktuális munkakönyvtár teljes elérési útját.

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

Tulajdonság értéke

A könyvtár elérési útja.

Kivételek

Egy üres sztringre ("") próbált meg beállítani.

A beállítási kísérlet a következőre nulltörtént: .

I/O-hiba történt.

Olyan helyi elérési utat próbált meg beállítani, amely nem található.

A hívó nem rendelkezik a megfelelő engedéllyel.

Példák

Az alábbi példa a tulajdonság beállítását CurrentDirectory mutatja be.

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.

Megjegyzések

Definíció szerint, ha ez a folyamat egy helyi vagy hálózati meghajtó gyökérkönyvtárában kezdődik, a tulajdonság értéke a meghajtó neve, amelyet egy záró perjel követ (például "C:\"). Ha ez a folyamat egy alkönyvtárban kezdődik, a tulajdonság értéke a meghajtó és az alkönyvtár elérési útja, záró perjel nélkül (például "C:\mySubDirectory").

A következőre érvényes: