System.IO.Directory.SetCurrentDirectory Method

Sets the application's current working directory to the specified directory.

Syntax

public static void SetCurrentDirectory (string path)

Parameters

path
The path to which the current working directory is set.

Exceptions

TypeReason
ArgumentException path is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.
ArgumentNullException path is null.
System.IO.FileNotFoundException path was not found.
System.IO.IOExceptionAn I/O error occurred while performing the operation.
System.IO.PathTooLongExceptionThe length of path or the absolute path information for path exceeds the system-defined maximum length.
System.Security.SecurityExceptionThe caller does not have the required permission to access unmanaged code.

Remarks

When the application terminates, the working directory is restored to its original location (the directory where the process was started).

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see Directory.GetCurrentDirectory.

Trailing spaces are removed from the end of the path parameter before setting the directory.

The path parameter is not case-sensitive.

If you are setting the directory to a drive with removable media (for example, to "A:" for a floppy disk drive or "E:" for a CD-ROM drive), you can determine whether the drive is ready by using the DriveInfo.IsReady property.

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0