我们经常会用它来合并路径。这个合并路径会自己跟据操作系统,把合适的路径分割符加进来
static async Task Main(string[] args)
{
var path = Path.Combine("abc", "dd");
Console.WriteLine(path);
}
windows下 输出 abc\dd linux 下输出的是 abc/dd
static async Task Main(string[] args)
{
var extension = Path.GetExtension("asdf/sdfsdf/sdf.png");
Console.WriteLine(extension);
}
static async Task Main(string[] args)
{
var fileName = Path.GetFileName("d:/as/aa/abc.txt");
Console.WriteLine(fileName);//abc.txt
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension("d:/as/aa/abc.txt");
Console.WriteLine(fileNameWithoutExtension);//abc
}
static async Task Main(string[] args)
{
var tempFile = Path.GetTempFileName();
Console.WriteLine(tempFile);
}