C# 获取文件名、目录、后缀、无后缀文件名、扩展名、根目录等


//获取当前运行程序的目录
string fileDir = Environment.CurrentDirectory;
Console.WriteLine("当前程序目录:"+fileDir);

//一个文件目录
string filePath = "C:\\JiYF\\BenXH\\BenXHCMS.xml";

string str = "获取文件的全路径:" + Path.GetFullPath(filePath); //-->C:\JiYF\BenXH\BenXHCMS.xml


str = "获取文件所在的目录:" + Path.GetDirectoryName(filePath); //-->C:\JiYF\BenXH


str = "获取文件的名称含有后缀:" + Path.GetFileName(filePath); //-->BenXHCMS.xml


str = "获取文件的名称没有后缀:" + Path.GetFileNameWithoutExtension(filePath); //-->BenXHCMS

str = "获取路径的后缀扩展名称:" + Path.GetExtension(filePath); //-->.xml

str = "获取路径的根目录:" + Path.GetPathRoot(filePath); //-->C:\


posted @ 2018-12-06 13:32  蹦蹦郭  阅读(2467)  评论(0编辑  收藏  举报