Environment.CurrentDirectory Propiedad

Definición

Obtiene o establece la ruta de acceso completa del directorio de trabajo actual.

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

Valor de propiedad

Ruta de acceso al directorio.

Excepciones

Intentó establecerse en una cadena vacía ("").

Se intentó establecer en null.

Error de E/S.

Se intentó establecer una ruta de acceso local que no se encuentra.

El autor de la llamada no dispone del permiso adecuado.

Ejemplos

En el ejemplo siguiente se muestra cómo establecer la CurrentDirectory propiedad .

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.

Comentarios

Por definición, si este proceso se inicia en el directorio raíz de una unidad de red o local, el valor de esta propiedad es el nombre de la unidad seguido de una barra diagonal final (por ejemplo, "C:\"). Si este proceso se inicia en un subdirectorio, el valor de esta propiedad es la unidad y la ruta de acceso del subdirectorio, sin una barra diagonal final (por ejemplo, "C:\mySubDirectory").

Se aplica a