C#文件路径获取函数和文件名字获取函数
来源:互联网 发布:真飞鸟知乎 编辑:程序博客网 时间:2024/05/16 17:19
1. 获取绝对文件路径
System.IO.Path.GetFullPath(string path)
string fileName = "myfile.ext";
string path1 = @"mydir";
string path2 = @"\mydir";
string fullPath;
fullPath = Path.GetFullPath(path1);
fullPath = Path.GetFullPath(fileName);
fullPath = Path.GetFullPath(path2);
2. 获取文件名字(得到指定路径内的文件名,不包括扩展名)
System.IO.Path.GetFileNameWithoutExtension(string path)
string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string result;
result = Path.GetFileNameWithoutExtension(fileName);
result = Path.GetFileName(path);
3.获得包含 path 目录信息的string 或者为空引用
System.IO.Path.GetDirectoryName(string path)
string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string rootPath = @"C:\";
string directoryName;
directoryName = Path.GetDirectoryName(fileName);
directoryName = Path.GetDirectoryName(path);
directoryName = Path.GetDirectoryName(rootPath);
4.合并两个路径字符串。
System.IO.Path.Combine(String path1, String path2)
作者:绿茶叶
出处:http://www.cnblogs.com/greenteaone/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
- C#文件路径获取函数和文件名字获取函数
- C#文件路径获取函数和文件名字获取函数
- bash中获取文件路径和文件命的函数
- MFC中为ListControl控件添加NM_CLICK消息选择控件中的文件并获取文件路径和文件名字
- UC编程5-fcntl函数获取文件状态和加锁解锁/dup函数和文件映射
- 获取OpenFileDialog的文件名和文件路径
- C# 根据包含文件的路径和文件的名称的字符串获取文件名称的几种方法
- C#中OpenFileDialog获取文件名和文件路径的常用方法
- C#中OpenFileDialog获取文件名和文件路径的常用方法
- C#中OpenFileDialog获取文件名和文件路径的常用方法.
- 在Servlet中获取Web路径和文件真实路径
- Windows API函数获取指定文件目录下文件路径(vc6.0通过)
- C#如何获取C++DLL中的函数名字
- php 遍历文件夹及文件,获取文件名和文件路径存入数据库中
- php 遍历文件夹及文件,获取文件名和文件路径存入数据库中
- 文件编程:路径获取getcwd()函数
- 获取文件路径函数之GetModuleFileName()
- C#获取文件路径
- Opencv研读笔记:haartraining程序之cvCreateMTStumpClassifier函数详解(弱分类器创建)~
- 关于对表的读写权限的控制示例演示
- mac 安装xampp mysql无法启动问题
- [Leetcode]Add Two Numbers
- 一些常用的宏
- C#文件路径获取函数和文件名字获取函数
- BigDecimal的加减乘除
- 国外软件外包项目网站(适用软件兼职)
- rabbimq集群关闭 启动 重置
- 【c++程序】多重继承容易产生两义性
- Android获取版本号
- QQ客服
- BZOJ 1270 Beijing Wc 2008 雷涛的小猫 动态规划
- 机器视觉开源代码集合