C# System.IO.Path
Path的常用方法
函数列表

对一个路径做相应操作,包括文件路径,目录路径,通常会用到Path这个类, 本文列举一些常用的操作。
获取指定路径字符串的目录信息
public static string GetDirectoryName(string path)
直接看几个示例了:
string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string rootPath = @"C:\";
Path.GetDirectoryName(fileName); //返回:'C:\mydir'
Path.GetDirectoryName(path); //返回:'C:\mydir'
Path.GetDirectoryName(rootPath); //返回:''
获取指定路径字符串的扩展名
public static string GetExtension(string path)
合并两个字符路径字符串
public static string Combine(string path1,string path2)
更改路径字符串的扩展名
public static string ChangeExtension(string path,string extension)
常用方法二
Path//对文件或目录的路径进行操作(很方便)【字符串】
修改后缀,非重命名文件
string s = Path.ChangeExtension(@"C:\temp\F3.png", "jpg");
组合在一起.c:\temp\a.jpg
string s = Path.Combine(@"c:\temp","a.jpg");
获得文件的路径
Path.GetDirectoryName(@"c:\temp\a.jpg");
其他方法
string GetExtension(string path) 得到文件的扩展名
string GetFileName(string path) 得到文件路径的文件名部分
string GetFileNameWithoutExtension(string path) 得到去除扩展名的文件名
string GetFullPath(string path) 得到文件的全路径。可以根据相对路径获得绝对路径。(比如:路径中含有../../之类的,可以得到绝对路径)
string GetTempFileName() 得到一个唯一的临时文件名(*)
string GetTempPath() 得到临时文件夹的路径(*)
MSDN资料
MSDN:http://msdn.microsoft.com/zh-cn/library/System.IO.Path_methods(v=vs.80).aspx
C# System.IO.Path的更多相关文章
- C#、.Net代码精简优化(空操作符(??)、as、string.IsNullOrEmpty() 、 string.IsNullOrWhiteSpace()、string.Equals()、System.IO.Path 的用法)
一.空操作符(??)在程序中经常会遇到对字符串或是对象判断null的操作,如果为null则给空值或是一个指定的值.通常我们会这样来处理: .string name = value; if (name ...
- System.IO.Path文件路径类
Path类的静态属性和方法,此类操作不影响物料文件. 属性 char a = System.IO.Path.VolumeSeparatorChar;//: char b = System.IO.Pat ...
- C#使用System.IO.Path获取文件路径、文件名
class Program { static void Main(string[] args) { //获取当前运行程序的目录 string fileDir = Environment.Current ...
- [原]System.IO.Path.Combine 路径合并
使用 ILSpy 工具查看了 System.IO.Path 类中的 Combine 方法 对它的功能有点不放心,原方法实现如下: // System.IO.Path /// <summary&g ...
- 使用System.IO.Combine(string path1, string path2, string path3)四个参数的重载函数提示`System.IO.Path.Combine(string, string, string, string)' is inaccessible due to its protection level
今天用Unity5.5.1开发提取Assets目录的模块,使用时采用System.IO.Path.Combine(string, string, string, string)函数进行路径生成 明明是 ...
- System.IO.Path类
System.IO.Path为路径的操作封装了很多很有的东西,利用该类提供的方法能够快速处理路径操作的问题.下面详细了解一下. 1.属性 属性太复杂了,反映什么系统平台的信息,看不懂,等以后看得懂了再 ...
- System.IO.Path 文件名、路径、扩展名 处理
string filePath =@"E:/Randy0528/中文目录/JustTest.rar"; 更改路径字符串的扩展名.System.IO.Path.ChangeExten ...
- System.IO.Path
System.IO.Path 分类: C#2011-03-23 10:54 1073人阅读 评论(0) 收藏 举报 扩展磁盘string2010c System.IO.Path提供了一些处理文件名和路 ...
- System.IO.Path 操作
System.IO.Path 分类: C#2011-03-23 10:54 1073人阅读 评论(0) 收藏 举报 扩展磁盘string2010c System.IO.Path提供了一些处理文件名和路 ...
- System.IO.Path 文件名、路径、扩展名处理
string filePath =@"E:/Randy0528/中文目录/JustTest.rar"; 更改路径字符串的扩展名.System.IO.Path.ChangeExten ...
随机推荐
- mysql使用pdo简单封装select语句
最终代码: function pdo_array_query($pdo, $table_name, $data, $fields=array('*')){ //Will contain SQL sni ...
- linux下更改时区
起因: 装系统时一走神把时区选错了,导致时间不正确,但是又不想重装,所以找了一下解决方法. 解决方案: 我的环境时这样的,其他的环境没试过. [root@werserver01 ~]# cat /et ...
- spring scope 作用域
转自:http://www.cnblogs.com/qq78292959/p/3716827.html 今天研究了一下scope的作用域.默认是单例模式,即scope="singleton& ...
- nginx报错整理
一. 1.线上有个域名出现一个访问报错: 413 Payload Too Large 这里贴一下关于这个报错的解释: The 413 (Payload Too Large) status code i ...
- 1657 Distance on Chessboard(简单计算题)
描述 国际象棋的棋盘是黑白相间的8 * 8的方格,棋子放在格子中间.如下图所示:王.后.车.象的走子规则如下: 王:横.直.斜都可以走,但每步限走一格. 后:横.直.斜都可以走,每步格数不受限制. 车 ...
- UIKit框架之NSObject
首先学习NSObject // // ViewController.m // localization // // Created by City--Online on 15/5/15. // Cop ...
- 【angular5项目积累总结】结合adal4实现http拦截器(token)
import { Injectable } from '@angular/core'; import { HttpEvent, HttpInterceptor, HttpHandler, HttpRe ...
- MySQL的相关应用
本文主要介绍数据库中MySQL的基础知识,包括数据插入.数据更新.数据删除.数据查询.函数.CASE语句.表连接.子查询. 一.数据插入(insert 语句) 首先我创建一个表,如下: 接着,进行数据 ...
- 【学习笔记】---老男孩学Python,day1
老早同学就推荐自己学编程了,因为各种事耽误了几年的时间,也可以说自己没有居安思危的意识吧… 直到今年2月份决定掏钱学线上课,但是又被兼职打断了,公司忙,兼职事多,拖来拖去只能把课程延期.这一拖就到了五 ...
- Code Signal_练习题_digitDegree
Let's define digit degree of some positive integer as the number of times we need to replace this nu ...