How to Set Current directory and how to get root directory
The following code example determines How to set current directory and how to get root directory with using static class directory.Step 1:-Add the following namespaces
using System;
using System.IO;Step 2:-Initilizes variables
Create string for a directory. This value should be an existing directory
// or the sample will throw a DirectoryNotFoundException.
string dir = @"C:\test";Step 3:-Check the existence , Deletion and Creation of directories
//Set the current directory
Directory.SetCurrentDirectory(dir);Step 3:-TO display result
Console.WriteLine("Root directory: {0}", Directory.GetDirectoryRoot(dir));
Console.WriteLine("Current directory: {0}", Directory.GetCurrentDirectory());
Special Note:- Directory class is static and all methods can be called without creating any instance of this class
