macT
[csharp] view plain copy
class Program  
    {  
        static void Main(string[] args)  
        {  
  
            //获取当前运行程序的目录  
            string fileDir = Environment.CurrentDirectory;  
            Console.WriteLine("当前程序目录:"+fileDir);  
              
            //一个文件目录  
            string filePath = "C:\\JiYF\\BenXH\\BenXHCMS.xml";  
            Console.WriteLine("该文件的目录:"+filePath);  
  
            string str = "获取文件的全路径:" + Path.GetFullPath(filePath);   //-->C:\JiYF\BenXH\BenXHCMS.xml  
            Console.WriteLine(str);  
            str = "获取文件所在的目录:" + Path.GetDirectoryName(filePath); //-->C:\JiYF\BenXH  
            Console.WriteLine(str);  
            str = "获取文件的名称含有后缀:" + Path.GetFileName(filePath);  //-->BenXHCMS.xml  
            Console.WriteLine(str);  
            str = "获取文件的名称没有后缀:" + Path.GetFileNameWithoutExtension(filePath); //-->BenXHCMS  
            Console.WriteLine(str);  
            str = "获取路径的后缀扩展名称:" + Path.GetExtension(filePath); //-->.xml  
            Console.WriteLine(str);  
            str = "获取路径的根目录:" + Path.GetPathRoot(filePath); //-->C:\  
            Console.WriteLine(str);  
            Console.ReadKey();  
  
        }  
    }  

 

分类:

技术点:

相关文章:

  • 2021-12-10
  • 2021-10-20
  • 2021-09-07
  • 2021-09-28
  • 2021-12-30
  • 2021-11-27
  • 2021-12-13
  • 2021-10-20
猜你喜欢
  • 2021-12-10
  • 2021-12-10
  • 2021-08-03
  • 2021-11-22
  • 2021-10-20
  • 2022-01-04
相关资源
相似解决方案