
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 get the file name in C#
Set the path name in a string −
string myPath = "D:\\new\\quiz.txt";
Now, use the GetFileName() method to get the name of the file −
Path.GetFileName(myPath)
The following is the complete code −
Example
using System; using System.IO; namespace Demo { class Program { static void Main(string[] args) { string myPath = "D:\\new\\quiz.txt"; // get extension Console.WriteLine("Extension: "+Path.GetExtension(myPath)); // get path Console.WriteLine("File Path: "+Path.GetFileName(myPath)); } } }
Output
Extension: .txt File Path: D:\new\quiz.txt
- Related Questions & Answers
- C# Program to get the name of the drive
- C program to change the file name using rename() function
- C# program to get the extension of a file in C#
- C# Program to get the name of root directory
- C# Program to get information about a file
- Java Program to get name of specified file or directory
- Get file extension name in Java
- C# Program to get the last write time of a file
- C# Program to get the last access time of a file
- Java Program to get the name of the parent directory of the file or directory
- Get the name of the file and path in Java
- How to get the name of the current executable in C#?
- C# Program to display the name of the directory
- How to get the maximum file name length limit using Python?
- How to get file name from a path in PHP?
Advertisements