C#根据文件路径获取文件名称

string filePath = @"D:\Data\T01.jpg";
Path.GetFullPath(filePath);
//=> D:\Data\T01.jpg
Path.GetDirectoryName(filePath));
//=> D:\Data
Path.GetFileName(filePath);
//=> T01.jpg
Path.GetFileNameWithoutExtension(filePath);
//=> T01
Path.GetExtension(filePath);
//=> .jpg
Path.GetPathRoot(filePath);
//=> D:\
filePath.Substring(folderPath.LastIndexOf(@"\") + 1);
//=> Data
 

 

posted on 2020-07-02 21:18  嘟嘟他爸  阅读(486)  评论(0编辑  收藏  举报

导航