C#中的文件路径获取函数和文件名字获取函数小结
2023-06-13 09:15:41 时间
1.获取绝对文件路径
System.IO.Path.GetFullPath(stringpath)
stringfileName="myfile.ext";
stringpath1=@"mydir";
stringpath2=@"\mydir";
stringfullPath;
fullPath=Path.GetFullPath(path1);
fullPath=Path.GetFullPath(fileName);
fullPath=Path.GetFullPath(path2);
2.获取文件名字(得到指定路径内的文件名,不包括扩展名)
System.IO.Path.GetFileNameWithoutExtension(stringpath)
stringfileName=@"C:\mydir\myfile.ext";
stringpath=@"C:\mydir\";
stringresult;
result=Path.GetFileNameWithoutExtension(fileName);
result=Path.GetFileName(path);
3.获得包含path目录信息的string或者为空引用
System.IO.Path.GetDirectoryName(stringpath)
stringfileName=@"C:\mydir\myfile.ext";
stringpath=@"C:\mydir\";
stringrootPath=@"C:\";
stringdirectoryName;
directoryName=Path.GetDirectoryName(fileName);
directoryName=Path.GetDirectoryName(path);
directoryName=Path.GetDirectoryName(rootPath);
4.合并两个路径字符串。
System.IO.Path.Combine(Stringpath1,Stringpath2)
相关文章
- C#实现十六进制与十进制相互转换以及及不同进制表示案例分享
- c#面试题抽象类和接口的区别-金三银四面试:C#程序员经常遇到的30道基础面试题,想你所想
- c#下将.cs文件编译成dll
- javascript实现的像java、c#之类的sleep暂停的函数代码
- C#读取中文字符及清空缓冲区的实现代码
- C#VB实现10进制16进制之间互相转换
- C#数据导入/导出Excel文件及winForm导出Execl总结
- C#去除首尾字符或字符串的方法
- 对c#中委托的理解
- C#如何判断两个文件内容是否相同的方法
- c#之圆形无标题栏椭圆窗体的实现详解
- C#判断文件路径是否存在或者判断文件是否存在的方法
- C#删除文件夹和文件到回收站示例
- c#使用资源文件的示例
- C#导入导出EXCEL文件的代码实例
- c#rsa注册实现加密文字
- C#采用FileSystemWatcher实现监视磁盘文件变更的方法
- C#针对xml文件转化Dictionary的方法
- C#中子类调用父类的实现方法