Environment.CurrentDirectory Environment.CurrentDirectory Environment.CurrentDirectory Environment.CurrentDirectory Property

Definition

Gets or sets the fully qualified path of the current working directory.

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

Property Value

A string containing a directory path.

Exceptions

Attempted to set to an empty string ("").

The caller does not have the appropriate permission.

Examples

The following example demonstrates setting the CurrentDirectory property.

using namespace System;
using namespace System::IO;

void main()
{
      // Change the directory to %WINDIR%
      Environment::CurrentDirectory = Environment::GetEnvironmentVariable( "windir" );
      DirectoryInfo^ info = gcnew DirectoryInfo( "." );

      Console::WriteLine("Directory Info:   {0}", info->FullName);
}
// The example displays output like the following:
//        Directory Info:   C:\windows
using System;
using System.IO;

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

      Console.WriteLine("Directory Info:   " + info.FullName);
   }
}
// The example displays output like the following:
//        Directory Info:   C:\windows
Imports System.IO

Module Example
   Public Sub Main()
        ' Change the directory to %WINDIR%
        Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir")
        Dim info As New DirectoryInfo(".")
        Console.WriteLine("Directory Info:   " + info.FullName)
   End Sub
End Module
' The example displays output like the following:
'        Directory Info:   C:\windows

Remarks

By definition, if this process starts in the root directory of a local or network drive, the value of this property is the drive name followed by a trailing slash (for example, "C:\"). If this process starts in a subdirectory, the value of this property is the drive and subdirectory path, without a trailing slash (for example, "C:\mySubDirectory").

Security

SecurityPermission
for writing to files or directories in a set operation. Associated enumeration: UnmanagedCode

FileIOPermission
for access to the information in the path itself in a get operation. Associated enumeration: PathDiscovery

Applies to