常用方法
  • GetFileName() 获取文件名
  • GetFileNameWithoutExtension () 获取文件扩展名
  • GetExtension() 获取扩展名
  • GetFullPath() 获取全路径
  • Combine() 拼接路径
示例代码
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string pathStr = @"c:\abc.jpg";
            // 获取文件名
            Console.WriteLine(Path.GetFileName(pathStr));
            // 获取文件扩展名 
            Console.WriteLine(Path.GetFileNameWithoutExtension(pathStr));
            // 获取扩展名
            Console.WriteLine(Path.GetExtension(pathStr));
            // 获得全路径
            Console.WriteLine(Path.GetFullPath(pathStr));
            // 拼接路径
            Console.WriteLine(Path.Combine(@"c:\" + "123.png"));
        }
    }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.