zoukankan      html  css  js  c++  java
  • C# 截取带路径的文件名字,扩展名,等等 的几种方法

     C#对磁盘IO操作的时候,经常会用到这些,路径,文件,文件名字,文件扩展名.
    
        之前,经常用切割字符串来实现,
    
        可是经常会弄错. 尤其是启始位置,多少个字节,经常弄晕.
    
     
    
    下面这种方法貌似比较简便:
    
     
    
    string filePath = @"E:Randy0528中文目录JustTest.rar";
    Response.Write("文件路径:"+filePath);
    Response.Write("
    更改路径字符串的扩展名。
    ");
    Response.Write(System.IO.Path.ChangeExtension(filePath, "txt"));
    Response.Write("
    返回指定路径字符串的目录信息。。
    ");
    Response.Write(System.IO.Path.GetDirectoryName(filePath));
    Response.Write("
    返回指定的路径字符串的扩展名。
    ");
    Response.Write(System.IO.Path.GetExtension(filePath));
    Response.Write("
    返回指定路径字符串的文件名和扩展名。
    ");
    Response.Write(System.IO.Path.GetFileName(filePath));
    Response.Write("
    返回不具有扩展名的指定路径字符串的文件名。
    ");
    Response.Write(System.IO.Path.GetFileNameWithoutExtension(filePath));
    Response.Write("
    获取指定路径的根目录信息。
    ");
    Response.Write(System.IO.Path.GetPathRoot(filePath));
    Response.Write("
    返回随机文件夹名或文件名。
    ");
    Response.Write(System.IO.Path.GetRandomFileName());
    Response.Write("
    创建磁盘上唯一命名的零字节的临时文件并返回该文件的完整路径。
    ");
    Response.Write(System.IO.Path.GetTempFileName());
    Response.Write("
    返回当前系统的临时文件夹的路径。
    ");
    Response.Write(System.IO.Path.GetTempPath());
    Response.Write("
    确定路径是否包括文件扩展名。
    ");
    Response.Write(System.IO.Path.HasExtension(filePath));
    Response.Write("
    获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。
    ");
    Response.Write(System.IO.Path.IsPathRooted(filePath));
    文件路径:E:Randy0528中文目录JustTest.rar
    C 文件路径、文件名、扩展名 - skyroom - lantianroom更改路径字符串的扩展名。
    C 文件路径、文件名、扩展名 - skyroom - lantianroomE:Randy0528中文目录JustTest.txt
    C 文件路径、文件名、扩展名 - skyroom - lantianroom返回指定路径字符串的目录信息。。
    C 文件路径、文件名、扩展名 - skyroom - lantianroomE:Randy0528中文目录
    C 文件路径、文件名、扩展名 - skyroom - lantianroom返回指定的路径字符串的扩展名。
    C 文件路径、文件名、扩展名 - skyroom - lantianroom.rar
    C 文件路径、文件名、扩展名 - skyroom - lantianroom返回指定路径字符串的文件名和扩展名。
    C 文件路径、文件名、扩展名 - skyroom - lantianroomJustTest.rar
    C 文件路径、文件名、扩展名 - skyroom - lantianroom返回不具有扩展名的指定路径字符串的文件名。
    C 文件路径、文件名、扩展名 - skyroom - lantianroomJustTest
    C 文件路径、文件名、扩展名 - skyroom - lantianroom获取指定路径的根目录信息。
    C 文件路径、文件名、扩展名 - skyroom - lantianroomE:
    C 文件路径、文件名、扩展名 - skyroom - lantianroom返回随机文件夹名或文件名。
    C 文件路径、文件名、扩展名 - skyroom - lantianroomct2h5b2h.sed
    C 文件路径、文件名、扩展名 - skyroom - lantianroom创建磁盘上唯一命名的零字节的临时文件并返回该文件的完整路径。
    C 文件路径、文件名、扩展名 - skyroom - lantianroomC:Documents and SettingsRandyLocal SettingsTemp	mpAD.tmp
    C 文件路径、文件名、扩展名 - skyroom - lantianroom返回当前系统的临时文件夹的路径。
    C 文件路径、文件名、扩展名 - skyroom - lantianroomC:Documents and SettingsRandyLocal SettingsTemp
    C 文件路径、文件名、扩展名 - skyroom - lantianroom确定路径是否包括文件扩展名。
    C 文件路径、文件名、扩展名 - skyroom - lantianroomTrue
    C 文件路径、文件名、扩展名 - skyroom - lantianroom获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。
    C 文件路径、文件名、扩展名 - skyroom - lantianroomTrue
  • 相关阅读:
    01Angular开发环境配置
    不再显示广告案例(php操作cookie)
    php操作 cookie
    JPush Android 推送如何区分开发、生产环境
    10 分钟实现一个自己的服务器监控器
    iOS 轻松使用 App 数据统计
    认识本质:黑天鹅、关键时刻与张小龙的产品观
    C# 服务端推送,十步十分钟,从注册到推送成功
    聊天界面-自适应文字
    极光推送的角标问题——让人又爱又恨的小红点
  • 原文地址:https://www.cnblogs.com/qq458978/p/4520185.html
Copyright © 2011-2022 走看看