当前位置:网站首页>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"
边栏推荐
- C专家编程 第3章 分析C语言的声明 3.6 typedef int x[10]和#define x int[10]的区别
- Small Tools (4) integrated Seata1.5.2 distributed transactions
- Tolstoy: There are only two misfortunes in life
- Selective Search学习笔记
- MATLAB | 七夕节快到了,还不给朋友安排上这个咕呱小青蛙?
- [Unity Getting Started Plan] Basic Concepts (8) - Tile Map TileMap 02
- 简易网络传输方法
- 滑环安装注意事项
- 详谈RDMA技术原理和三种实现方式
- 兄弟组件通信context
猜你喜欢
Detailed ReentrantLock
想进阿里?先来搞懂一下分布式事务
机器人开发--Universal Scene Description(USD)
#夏日挑战赛# HarmonyOS 实现一个绘画板
[Unity Getting Started Plan] Basic Concepts (8) - Tile Map TileMap 01
高效的组织信息共享知识库是一种宝贵的资源
Web3 安全风险令人生畏?应该如何应对?
[QT] Qt project demo: data is displayed on the ui interface, double-click the mouse to display specific information in a pop-up window
vector类
TiKV & TiFlash accelerate complex business queries丨TiFlash application practice
随机推荐
To participate in sweepstakes, incoming new programmers magazine welfare!
MySQL窗口函数
Small Tools (4) integrated Seata1.5.2 distributed transactions
C专家编程 第3章 分析C语言的声明 3.8 理解所有分析过程的代码段
When mobile applications go overseas, is your "network optimization" holding back?
Windows 事件查看器记录到 MYSQL
MySQL窗口函数 OVER()函数介绍
MySQL窗口函数 PARTITION BY()函数介绍
中小微企业如何简单便捷、低成本实现数字化?360视觉云有妙招
一文看懂推荐系统:召回03:基于用户的协同过滤(UserCF),要计算用户之间的相似度
超分重建数据集
组件通信-父传子组件通信
13 and OOM simulation
Difference and performance comparison between HAL and LL library of STM32
【带你了解SDN和网络虚拟化】
DataGrip:非常好用的数据库工具,安装与使用教程,亮点介绍
正向代理与反向代理
CPU个数_核心数_线程数之间的关系
高效的组织信息共享知识库是一种宝贵的资源
【There is no tracking information for the current branch. Please specify which branch you want to 】