要获取不带路径的文件名,可以使用 Path.GetFileName 方法。以下是一个示例:

string filePath = @"C:\Users\Username\Documents\example.txt";
string fileName = Path.GetFileName(filePath);
Console.WriteLine(fileName);

输出将是:

example.txt

使用 Path.GetFileName 方法,你可以从文件路径中提取文件名,而不包括路径信息。

C# 用PathGet 方法获取不带路径的文件名

原文地址: https://www.cveoy.top/t/topic/iyE2 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录