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 妈妈横幅生日祝福语简短