C#程序获取C#中的文件名
在字符串中设置路径名-
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
热门推荐
10 家长祝福语大全简短内容
11 节日祝福语幽默简短的
12 婚庆花篮祝福语简短大气
13 初八祝福语简短语
14 比较简短浪漫的祝福语
15 哥哥考大学祝福语简短
16 怀念青春祝福语简短
17 发廊元旦祝福语大全简短
18 祖国生日祝福语简短英文