zoukankan      html  css  js  c++  java
  • 获取文件路径

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

    //一个文件目录
    string filePath = "C:\JiYF\BenXH\BenXHCMS.xml";
    Console.WriteLine("该文件的目录:"+filePath);

    string str = "获取文件的全路径:" + Path.GetFullPath(filePath); //-->C:JiYFBenXHBenXHCMS.xml
    Console.WriteLine(str);
    str = "获取文件所在的目录:" + Path.GetDirectoryName(filePath); //-->C:JiYFBenXH
    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();

  • 相关阅读:
    洛谷 P4484
    洛谷 P4900
    Codeforces 1500D
    Codeforces 1322D
    2021.9.30 Codeforces 中档题四道
    BZOJ 3729
    洛谷 P6276
    Codeforces 1511G
    C语言 typedef
    C语言 回调函数 callback
  • 原文地址:https://www.cnblogs.com/itclw/p/11533917.html
Copyright © 2011-2022 走看看