C# 路径中获取文件全路径、目录、扩展名、文件名称

//获取当前运行程序的目录

Application.StartupPath;
Environment.CurrentDirectory;

//一个文件目录
string filePath = "C:\\JiYF\\BenXH\\BenXHCMS.xml";
System.IO.Path.GetFullPath(filePath);                                       //-->C:\JiYF\BenXH\BenXHCMS.xml
System.IO.Path.GetDirectoryName(filePath);                           //-->C:\JiYF\BenXH
System.IO.Path.GetFileName(filePath);                                    //-->BenXHCMS.xml
System.IO.Path.GetFileNameWithoutExtension(filePath);        //-->BenXHCMS
System.IO.Path.GetExtension(filePath);                                    //-->.xml
System.IO.Path.GetPathRoot(filePath);                                     //-->C:\


版权声明:本文为jindou910101原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。