C# Directory SetCurrentDirectory

Description

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

Syntax

Directory.SetCurrentDirectory has the following syntax.


public static void SetCurrentDirectory(
  string path
)

Parameters

Directory.SetCurrentDirectory has the following parameters.

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

Returns

Directory.SetCurrentDirectory method returns

Example

The following example illustrates how to set the current directory and display the directory root.


using System;/*from  w  w  w.j a v a2 s.  c  om*/
using System.IO;

public class DirectoryRoot
{
  public static void Main()
  {
    string dir = @"C:\test";    
    Directory.SetCurrentDirectory(dir);

    Console.WriteLine("Root directory: {0}", Directory.GetDirectoryRoot(dir));
    Console.WriteLine("Current directory: {0}", Directory.GetCurrentDirectory());
  }
}




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter