पथ का नाम एक स्ट्रिंग में सेट करें -
string myPath = "D:\\new\\quiz.txt";
अब, फ़ाइल का नाम प्राप्त करने के लिए GetFileName() विधि का उपयोग करें -
Path.GetFileName(myPath)
निम्नलिखित पूरा कोड है -
उदाहरण
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));
}
}
} आउटपुट
Extension: .txt File Path: D:\new\quiz.txt