C# 获取文件名、目录、后缀、无后缀文件名、扩展名、根目录等
2024-10-19 02:38:32
[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(); }
}
最新文章
- Dubbo学习之简单环境搭建
- javascript面向对象系列第二篇——创建对象的5种模式
- angularjs---select使用---默认值及联动
- Asp.net的request类
- Selenium调用Chrome,Firefox,IE
- EXTJS 3.0 资料 控件之 GridPanel属性与方法大全
- MVC入门
- c++怎样让返回对象的函数不调用拷贝构造函数
- ural 1073.Square Country(动态规划)
- Linux系统安装_Centos6.9
- Linux运维老司机:CentOS6.9配置安装并配置Rsync
- mac配置自带vim高亮显示
- UEFI Shell命令操作总结
- vue脚手架的使用
- OO最后一次作业
- 「洛谷P1516」 青蛙的约会
- 1-express学习
- over()的用法
- libvirt的security
- Applese走迷宫-bfs
热门文章
- 【转】每天一个linux命令(15):tail 命令
- 使用过的bug跟踪系统
- webpack 遇到报错情况及解决
- osql执行数据库查询命令并保存到txt文件
- AppBox下调用HighCharts画曲线
- 洛谷 3706 [SDOI2017]硬币游戏——思路
- 启动ECLIPSE时,提示找到不 eclipse\jre\bin\javaw.exe
- vue 操作数组,原数组怎么不让它改变
- 第3章 文件I/O(5)_五种I/O模型
- ubuntu18.04 安装hadoop 2.7.3+hive 2.3.4