C#--Path目录路径常用操作

经常百度这个问题,经常记不住,以下是笔记:

参考:https://blog.csdn.net/u011976734/article/details/79654399

 

定义 string filePath =@"E:/project/test/20180322.jpg";

 

 方法  方法说明  结果
System.IO.Path.ChangeExtension(filePath, "txt")  更改路径字符串的扩展名 E:/project/test/20180322.txt
System.IO.Path.GetDirectoryName(filePath) 返回指定路径字符串的目录信息 E:/project/test/
System.IO.Path.GetExtension(filePath)  返回指定的路径字符串的扩展名  .jpg
System.IO.Path.GetFileName(filePath)  返回指定路径字符串的文件名和扩展名 20180322.jpg
System.IO.Path.GetFileNameWithoutExtension(filePath)  返回不具有扩展名的指定路径字符串的文件名  20180322
System.IO.Path.GetPathRoot(filePath) 获取指定路径的根目录信息  E:/
System.IO.Path.GetRandomFileName() 返回随机文件夹名或文件名   ct2h5b2h.sed
System.IO.Path.GetTempFileName()  创建唯一命名的零字节的临时文件并返回其绝对路径  C:/Documents and Settings/Randy/Local Settings/Temp/tmpAD.tmp
System.IO.Path.GetTempPath()  返回当前系统的临时文件夹的路径  C:/Documents and Settings/Randy/Local Settings/Temp/
System.IO.Path.HasExtension(filePath) 返回路径是否包括文件扩展名   True
System.IO.Path.IsPathRooted(filePath) 返回路径是绝对路径还是相对路径 Ture
System.IO.Path.Combine(@ "c: ", "b.txt ")  返回合并后的路径  C:/b.txt
System.IO.Path.GetFullPath("20180322.jpg")  查找文件并返回其绝对路径
E:/project/test/20180322.jpg
     

 

posted @ 2022-01-03 22:09  包子789654  阅读(182)  评论(0编辑  收藏  举报