当前位置:网站首页>C# 获取文件名和扩展名(后缀名)
C# 获取文件名和扩展名(后缀名)
2022-08-03 16:28:00 【雪墩墩】
string fullPath = @"d:\test\default.avi";
string filename = Path.GetFileName(fullPath);//返回带扩展名的文件名 "default.avi"
string extension = Path.GetExtension(fullPath);//扩展名 ".avi"
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fullPath);// 没有扩展名的文件名 "default"
string dirPath = Path.GetDirectoryName(filePath) //返回文件所在目录 "d:\test"
string fullPath1 = Path.Combine(@"d:\test", "default.avi") //返回 "d:\test\default.avi"
string fullPath2 = Path.GetFullPath("config.ini");//返回指定路径字符串的绝对路径
string Path = @"d:\test\default\project"; //目录
string name = Path.GetFileName( Path); //返回目录名 “project”
使用字符串截取:
string filePath= @"d:\test\default.avi";
string filename = filePath.Substring( filePath.LastIndexOf(@"\") + 1); //截取文件名 "default.avi"
边栏推荐
猜你喜欢
组件通信--下拉菜单案例
附录A 程序员工作面试的秘密
How to start an NFT collection
#夏日挑战赛#【FFH】OpenHarmony设备开发基础(四)启动流程
面试不再被吊打!这才是Redis分布式锁的七种方案的正确打开方式
为什么我强烈推荐使用智能化async?
To add digital wings to education, NetEase Yunxin released the overall solution of "Internet + Education"
How much do you know about the intelligent operation and maintenance service of data warehouse based on DMS?
Small Tools (4) integrated Seata1.5.2 distributed transactions
世界顶级级架构师编写2580页DDD领域驱动设计笔记,属实有牌面
随机推荐
protobuf 反射使用总结
#夏日挑战赛#【FFH】OpenHarmony设备开发基础(四)启动流程
C语言02、语句、函数
MATLAB | 七夕节快到了,还不给朋友安排上这个咕呱小青蛙?
"Avnet Embedded Weekly" Issue 276: 2022.07.25--2022.07.31
leetcode:189. 轮转数组
攻防世界----bug
Component communication - parent-child component communication
附录A 程序员工作面试的秘密
To add digital wings to education, NetEase Yunxin released the overall solution of "Internet + Education"
组件通信--下拉菜单案例
高薪程序员&面试题精讲系列132之微服务之间如何进行通信?服务熔断是怎么回事?你熟悉Hystrix吗?
Detailed explanation of ReentrantReadWriteLock
DataGrip:非常好用的数据库工具,安装与使用教程,亮点介绍
最强分布式锁工具:Redisson
DataGrip数据仓库工具
DAYU200 OpenHarmony标准系统HDMI全屏显示
机器人开发--Universal Scene Description(USD)
使用 PowerShell 将 Windows 转发事件导入 SQL Server
MySQL窗口函数 PARTITION BY()函数介绍