C# Program to get the name of root directory

CsharpProgrammingServer Side Programming

Use the RootDirectory property to get the name of the root directory.

Firstly, use DriveInfo to set the drive for which you want the root directory −

DriveInfo dInfo = new DriveInfo("C");

Now, the RootDirectory gives you the result −

dInfo.RootDirectory

Example

Here is the complete code −

using System;
using System.Linq;
using System.IO;
public class Demo {
   public static void Main() {
      DriveInfo dInfo = new DriveInfo("C");
      Console.WriteLine("Root Directory: "+dInfo.RootDirectory);
   }
}

Output

The following is the output −

C:\
raja
Published on 05-Sep-2018 07:19:13
Advertisements