路徑中獲取文件全路徑、目錄、擴展名、文件名稱


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace TBQDLKW
{
    class Program
    {
        static void Main(string[] args)
        {
            //一個文件目錄
            string filePath = @"C:\Users\JuYaNan\Desktop\DBCs\ST_CAN.dbc";
            Console.WriteLine("該文件的目錄:" + filePath);
            string str = "獲取文件的全路徑:" + Path.GetFullPath(filePath);
            Console.WriteLine(str);
            str = "獲取文件所在的目錄:" + Path.GetDirectoryName(filePath);
            Console.WriteLine(str);
            str = "獲取文件的名稱含有后綴:" + Path.GetFileName(filePath);
            Console.WriteLine(str);
            str = "獲取文件的名稱沒有后綴:" + Path.GetFileNameWithoutExtension(filePath);
            Console.WriteLine(str);
            str = "獲取路徑的后綴擴展名稱:" + Path.GetExtension(filePath);
            Console.WriteLine(str);
            str = "獲取路徑的根目錄:" + Path.GetPathRoot(filePath);
            Console.WriteLine(str);
            Console.ReadKey();
        }
    }
}

結果圖:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM