码迷,mamicode.com
首页 > 其他好文 > 详细

路径中获取文件全路径、目录、扩展名、文件名称

时间:2019-11-08 12:01:46      阅读:378      评论:0      收藏:0      [点我收藏+]

标签:collect   ons   oid   line   space   rgs   名称   style   getdir   

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();
        }
    }
}

结果图:

技术图片

路径中获取文件全路径、目录、扩展名、文件名称

标签:collect   ons   oid   line   space   rgs   名称   style   getdir   

原文地址:https://www.cnblogs.com/tbqdlkw/p/11819204.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!