Path类
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _02Path的使用方法 { class Program { static void Main(string[] args) { string str = @"E:dotNetStudy文件操作学习New.txt"; //获取文件名; string fileName = Path.GetFileName(str); Console.WriteLine(fileName); //获取文件目录; string dirName = Path.GetDirectoryName(str); Console.WriteLine(dirName); //获取文件目录完整路径; string dirPath = Path.GetFullPath(str); Console.WriteLine(dirPath); //获取文件扩展名; string fileExt = Path.GetExtension(str); Console.WriteLine(fileExt); //获取文件名不带扩展名; string fileName1 = Path.GetFileNameWithoutExtension(str); Console.WriteLine(fileName1); //组合文件名称 string cName = Path.Combine(@"E:a", "st.txt"); Console.WriteLine(cName); //输出:E:ast.txt Console.ReadKey(); } } }