zoukankan
html css js c++ java
C#编程技巧之常用文件名、路径处理方法
最近发现System.IO.Path提供了一些处理文件名和路径的方法,不敢独享拿出来跟大家分享一下!
PS:以前我都自己写函数方法 - -........
ASP.Net C#代码处
string
filePath
=
@"
E:\Randy0528\中文目录\JustTest.rar
"
;
Response.Write(
"
文件路径:
"
+
filePath);
Response.Write(
"
<br/>更改路径字符串的扩展名。<br/>
"
);
Response.Write(System.IO.Path.ChangeExtension(filePath,
"
txt
"
));
Response.Write(
"
<br/>返回指定路径字符串的目录信息。。<br/>
"
);
Response.Write(System.IO.Path.GetDirectoryName(filePath));
Response.Write(
"
<br/>返回指定的路径字符串的扩展名。<br/>
"
);
Response.Write(System.IO.Path.GetExtension(filePath));
Response.Write(
"
<br/>返回指定路径字符串的文件名和扩展名。<br/>
"
);
Response.Write(System.IO.Path.GetFileName(filePath));
Response.Write(
"
<br/>返回不具有扩展名的指定路径字符串的文件名。<br/>
"
);
Response.Write(System.IO.Path.GetFileNameWithoutExtension(filePath));
Response.Write(
"
<br/>获取指定路径的根目录信息。<br/>
"
);
Response.Write(System.IO.Path.GetPathRoot(filePath));
Response.Write(
"
<br/>返回随机文件夹名或文件名。<br/>
"
);
Response.Write(System.IO.Path.GetRandomFileName());
Response.Write(
"
<br/>创建磁盘上唯一命名的零字节的临时文件并返回该文件的完整路径。<br/>
"
);
Response.Write(System.IO.Path.GetTempFileName());
Response.Write(
"
<br/>返回当前系统的临时文件夹的路径。<br/>
"
);
Response.Write(System.IO.Path.GetTempPath());
Response.Write(
"
<br/>确定路径是否包括文件扩展名。<br/>
"
);
Response.Write(System.IO.Path.HasExtension(filePath));
Response.Write(
"
<br/>获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。<br/>
"
);
Response.Write(System.IO.Path.IsPathRooted(filePath));
执行结果
文件路径:E:\Randy0528\中文目录\JustTest.rar
更改路径字符串的扩展名。
E:\Randy0528\中文目录\JustTest.txt
返回指定路径字符串的目录信息。。
E:\Randy0528\中文目录
返回指定的路径字符串的扩展名。
.rar
返回指定路径字符串的文件名和扩展名。
JustTest.rar
返回不具有扩展名的指定路径字符串的文件名。
JustTest
获取指定路径的根目录信息。
E:\
返回随机文件夹名或文件名。
ct2h5b2h.sed
创建磁盘上唯一命名的零字节的临时文件并返回该文件的完整路径。
C:\Documents and Settings\Randy\Local Settings\Temp\tmpAD.tmp
返回当前系统的临时文件夹的路径。
C:\Documents and Settings\Randy\Local Settings\Temp\
确定路径是否包括文件扩展名。
True
获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。
True
查看全文
相关阅读:
UOJ.26.[IOI2014]Game(交互 思路)
Good Bye 2016 F.New Year and Finding Roots(交互)
Codeforces.835E.The penguin's game(交互 按位统计 二分)
Codeforces.744B.Hongcow's Game(交互 按位统计)
Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)
正睿OI 提高 Day1T3 ZYB玩字符串(DP)
划分vlan
2三层交换机实现vlan间的路由
交换机基础-交换机远程telnet
自动化运维环境的搭建问题处理
原文地址:https://www.cnblogs.com/Randy0528/p/695772.html
最新文章
js命名空间以及对象枚举 笔记
TypeScript 结构
TypeScript 接口(interface)
js递归预编译总结
TypeScript 泛型
TypeScript高级类型
TypeScript声明合并
ES6快速入门
BZOJ.2668.[CQOI2012]交换棋子(费用流zkw)
BZOJ.2437.[NOI2011]兔兔与蛋蛋游戏(二分图博弈 匈牙利)
热门文章
BZOJ.1443.[JSOI2009]游戏Game(二分图博弈 匈牙利)
洛谷.3381.[模板]最小费用最大流(zkw)
BZOJ.5120.[清华集训2017]无限之环(费用流zkw 黑白染色)
BZOJ.2756.[SCOI2012]奇怪的游戏(二分 黑白染色 最大流ISAP)
Manthan, Codefest 18 (Div 1 + Div 2) (A~E)
9.1 正睿提高2
Codeforces.633F.The Chocolate Spree(树形DP)
Codeforces.566F.Clique in the Divisibility Graph(DP)
Codeforces.520B.Two Buttons(正难则反)
Codeforces.666A.Reberland Linguistics(DP)
Copyright © 2011-2022 走看看