C# Program to display the name of the directory

CsharpProgrammingServer Side Programming

Firstly, use the DirectoryInfo that operates on Directories. The parameter set in it is the file path −

DirectoryInfo dir = new DirectoryInfo(@"D:\new\");

To get the name of the directory, use the Name property −

dir.Name

The following is the code to display the name of the directory −

Example

 Live Demo

using System.IO;
using System;
public class Program {
   public static void Main() {
      DirectoryInfo dir = new DirectoryInfo(@"D:\new\");
      // displaying the name of the directory
      Console.WriteLine(dir.Name);
   }
}

Output

D:\new\
raja
Published on 05-Sep-2018 11:23:39
Advertisements