- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
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\
- Related Articles
- C# Program to get the name of root directory
- Java Program to get the name of the parent directory of the file or directory
- C# Program to display name of Current Thread
- Java Program to get name of parent directory
- Java Program to get name of specified file or directory
- How to display the name of the Current Thread in C#?
- C# Program to display the Factors of the Entered Number
- How to display the current working directory in the Linux system?
- C# program to display the previous day
- C# program to display the next day
- C# Program to get the name of the drive
- Java Program to get the content of a directory
- C# Program to display the number of days in a month
- C# Program to display priority of Thread
- How to display a directory list in HTML?

Advertisements