Tell a joke, Path is actually a class in C#, a class about file path operations

In the C# language, the Path class is mainly used for some operations on file paths, and it is also a static class.
The commonly used properties and methods in the Path class are shown in the following figure:
Insert picture description here
Example:

using System;
using System.IO;

namespace MySpace
{
    
    
    class Progarm
    {
    
    
        static void Main(string[] args)
        {
    
    
            Console.WriteLine("请输入一个文件路径:");
            string path = Console.ReadLine();
            Console.WriteLine("不包含扩展名的文件名: " +
                Path.GetFileNameWithoutExtension(path));
            Console.WriteLine("文件扩展名:" +
                Path.GetExtension(path));
            Console.WriteLine("文件全名:" +
                Path.GetFileName(path));
            Console.WriteLine("文件路径:" +
                Path.GetDirectoryName(path));

            //更改文件扩展名
            string newPath = Path.ChangeExtension(path, "doc");
            Console.WriteLine("更改后的文件全名:" + Path.GetFileName(newPath));
        }
    }
}

operation result:
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_50188452/article/details/115023816