手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#中的文件路径获取函数和文件名字获取函数小结
C#中的文件路径获取函数和文件名字获取函数小结
摘要:1.获取绝对文件路径复制代码代码如下:System.IO.Path.GetFullPath(stringpath)stringfileNam...

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:mydirmyfile.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:mydirmyfile.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)

【C#中的文件路径获取函数和文件名字获取函数小结】相关文章:

C# 获取属性名的方法

C#获取全部目录和文件的简单实例

C# 泛型类(函数)的实例化小例子

C#中英文混合字符串截取函数

C# jpg缩略图函数代码

c# 共享状态的文件读写实现代码

C#操作config文件的具体方法

c#中的浮点型转整形的舍取 四舍五入和银行家舍入实现代码

C#中使用快速排序按文件创建时间将文件排序的源码

c#.net 常用函数和方法集

精品推荐
分类导航