一种在 C# 中获取文件名的方法
将路径名设为字符串 -
string myPath = "D:\
ew\quiz.txt";
现在,使用 GetFileName() 方法获取文件的文件名 -
Path.GetFileName(myPath)
以下是完成的代码 -
示例
using System;
using System.IO;
namespace Demo {
class Program {
static void Main(string[] args) {
string myPath = "D:\
ew\quiz.txt";
// get extension
Console.WriteLine("Extension: "+Path.GetExtension(myPath));
// get path
Console.WriteLine("File Path: "+Path.GetFileName(myPath));
}
}
}输出
Extension: .txt File Path: D:
ew\quiz.txt
广告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP