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 ...
随机推荐
- SpringDataJPA快速入门
访问我的博客 前言 之前在学习 SpringBoot 框架的时候,使用到了 SpringData JPA,但是当时只是简单的查询,没有用到稍微复杂的查询. JPA 的 JPQL 语法规则对于简单的查询 ...
- DROP TABLE 恢复【一】
当DROP TABLE指令敲下的时候,你很爽,你有考虑过后果么?如果该表真的没用,你DROP到无所谓,如果还有用的,这时你肯定吓惨了吧,如果你有备份,那么恭喜你,逃过一劫,如果没有备份呢?这时就该绝望 ...
- apk的php解析
<?php/****************************************************** * Android APK File Parser * Author: ...
- 使用CSS定位元素实现水平垂直居中效果
总结一下平时使用CSS技巧使元素达到水平居中效果 相对定位(或绝对定位)实现水平垂直居中: element{ position:relative; /*这个属性也可以是absolute*/ width ...
- springboot redis 缓存跨域丢失问题
对于前后端分离的项目,在开发阶段经常会遇到跨域的问题. 1.首先,对于后台的处理方式,第一种是用 @CrossOrigin 注解,@crossorigin是后端SpringMVC框架(需4.2版本以上 ...
- ActiveMQ Pub/Sub版的HelloWorld
1. pom.xml 这个和上一篇是一样的: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&qu ...
- Java类MemoryUsage查看虚拟机的使用情况
原文地址:https://www.cnblogs.com/xubiao/p/5465473.html Java类MemoryUsage,通过MemoryUsage可以查看Java 虚拟机的内存池的内存 ...
- 使用 ReentrantLock 和 Condition 实现一个阻塞队列
前言 从之前的阻塞队列的源码分析中,我们知道,JDK 中的阻塞队列是使用 ReentrantLock 和 Condition 实现了,我们今天来个简易版的.代码如下: 代码 public class ...
- [转]Microsoft SQL SERVER 2008 R2 REPORT SERVICE 匿名登录
本文转自:https://www.cnblogs.com/Zouzhe/p/5736070.html SQL SERVER 2008 R2 是微软目前最新的数据库版本,在之前的SQL SERVER 2 ...
- SQL Server T—SQL 基本编程
一 定义变量 declare @变量名 数据类型 例:declare @a int -- 变量名前必须有 @ 二 赋值 set @变量名 = 值 sele ...