博客
关于我
C# 文件处理专题
阅读量:91 次
发布时间:2019-02-26

本文共 903 字,大约阅读时间需要 3 分钟。

C#路径中获取文件全路径、目录、扩展名、文件名称 常用函数 需要引用System.IO   直接可以调用Path的静态方法


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

        }

    }

转载地址:http://fjnk.baihongyu.com/

你可能感兴趣的文章
Netty工作笔记0053---Netty核心模块梳理
查看>>
Netty工作笔记0054---EventLoop组件
查看>>
Netty工作笔记0055---Unpooled应用实例1
查看>>
Netty工作笔记0056---Unpooled应用实例2
查看>>
Netty工作笔记0057---Netty群聊系统服务端
查看>>
Netty工作笔记0058---Netty群聊系统客户端
查看>>
Netty工作笔记0059---Netty私聊实现思路
查看>>
Netty工作笔记0060---Netty心跳机制实例
查看>>
Netty工作笔记0060---Tcp长连接和短连接_Http长连接和短连接_UDP长连接和短连接
查看>>
Netty工作笔记0061---Netty心跳处理器编写
查看>>
Netty工作笔记0062---WebSocket长连接开发
查看>>
Netty工作笔记0063---WebSocket长连接开发2
查看>>
vue样式穿透 ::v-deep的具体使用
查看>>
Netty工作笔记0065---WebSocket长连接开发4
查看>>
Netty工作笔记0066---Netty核心模块内容梳理
查看>>
Vue基本使用---vue工作笔记0002
查看>>