11_Path类

Posted ncy123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了11_Path类相关的知识,希望对你有一定的参考价值。

 1 class Program
 2     {
 3         static void Main(string[] args)
 4         {
 5             string str=@"C:UsersAdministratorDeskto1.txt";
 6             //获得文件名
 7             Console.WriteLine(Path.GetFileName(str));
 8             //获得文件名但是不包含扩展名
 9             Console.WriteLine(Path.GetFileNameWithoutExtension(str));
10             //获得扩展名
11             Console.WriteLine(Path.GetExtension(str));
12             //获得文件夹的名称
13             Console.WriteLine(Path.GetDirectoryName(str));
14             //获得文件所在的全路径
15             Console.WriteLine(Path.GetFullPath(str));
16             //连接字符串作为新路径
17             Console.WriteLine(Path.Combine(@"c:a","b.txt"));
18         }
19     }

 

以上是关于11_Path类的主要内容,如果未能解决你的问题,请参考以下文章