C# Program to display the name of the directory


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

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

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:
ew\");       // displaying the name of the directory       Console.WriteLine(dir.Name);    } }

Output

D:
ew\

Updated on: 22-Jun-2020

87 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements