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
  • 相关阅读:
    XML属性
    4.9Java游戏项目练习
    关于JVM结构的学习
    HelloWorld之Struts2
    进程调度
    JVM垃圾回收总结
    学会阅读Java字节码
    关于产品需求文档的各种D
    刘强东学习亚马逊:控制供应链 技术是最大障碍
    JVM内存溢出的方式
  • 原文地址:https://www.cnblogs.com/qq458978/p/4520185.html
Copyright © 2011-2022 走看看