当前位置:首页 > 技术心得 > 正文内容

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

xjtudll8年前 (2018-06-18)技术心得14390

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();

        }

    }

 

参考资料:https://www.cnblogs.com/JiYF/p/6879139.html

扫描二维码推送至手机访问。

版权声明:本文由鸟的天空发布,如需转载请注明出处。

本文链接:http://xjtudll.cn/Exp/504/

标签: C#
分享给朋友:

“C#获取文件全路径、目录、扩展名、文件名称” 的相关文章

Xcode查找函数(方法)调用及被调用

Xcode查找函数(方法)调用及被调用

参考资料:http://stackoverflow.com/questions/7145045/find-method-references-in-xcode 这个功能有的说是 Find Caller,有的说是Find references,有的说是Find Usages 直白的讲,就是我需要知道这...

Storyboard已关联下面的TableView,为什么TabView的Cell显示不出来

问题: Storyboard已关联下面的TableView,为什么TabView的Cell显示不出来 原因及解决办法: 很简单,你的代码没有设置,SB里面的TableViewController要关联一个类,你需要添加好,并且注意下面这两个代理方法的返回值 - (NSInteger)numberO...

Android Studio删除Module

Android Studio删除Module

Android studio添加了一个module,结果添加错了,要删除才行,搞了半天不知道怎么弄。研究了很久,才搞清楚。 1 首先右键你要删除的Module。 2 我们往下看找到open module settings 3 弹出如图示的窗口 4 接着我们点击那个“-”...

Android调用系统自带的文件管理器进行文件选择

参考资料: http://blog.csdn.net/zqchn/article/details/8770913 http://www.xuebuyuan.com/929105.html 调用系统自带的文件管理器来选择文件         pri...

android动态改变ActionBar中MenuItem的图标

先调用方法:invalidateOptionsMenu(); 然后系统会自动回调方法:onPrepareOptionsMenu 在onPrepareOptionsMenu中改变MenuItem的图标即可。 例如: MenuItem item = menu.findItem(R.id.share);...

Xcode Warning: The Copy Bundle Resources build phase contains this target's Info.plist file

Xcode Warning: The Copy Bundle Resources build phase contains this target's Info.plist file

问题: 编译时,提示The Copy Bundle Resources build phase contains this target's Info.plist file 原因: Info.plist被添加到了Copy Bundle Resources里,原因不明。如图所示: 解决...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。