Path.Combine Method
public static string Combine (string path1, string path2);
Returns
The combined paths.
If one of the specified paths is a zero-length string, this method returns the other path.
If path2 contains an absolute path, this method returns path2.
如果不希望path2是绝对路径的话,可以用Path.IsPathRooted函数检查
A rooted path is file path that is fixed to a specific drive or UNIC path; it contrasts with a path that is relative to the current drive or working directory.
For example, on Windows systems, a rooted path begins with a backslash (for example, "\Documents") or a drive letter and colon (for example, "C:Documents").
Note that rooted paths can be either absolute (that is, fully qualified) or relative.
An absolute rooted path is a fully qualified path from the root of a drive to a specific directory.
A relative rooted path specifies a drive, but its fully qualified path is resolved against the current directory.
The following example illustrates the difference.
using System;
using System.IO; class Program
{
static void Main()
{
string relative1 = "C:Documents";
ShowPathInfo(relative1); string relative2 = "/Documents";
ShowPathInfo(relative2); string absolute = "C:/Documents";
ShowPathInfo(absolute);
} private static void ShowPathInfo(string path)
{
Console.WriteLine($"Path: {path}");
Console.WriteLine($" Rooted: {Path.IsPathRooted(path)}");
Console.WriteLine($" Fully qualified: {Path.IsPathFullyQualified(path)}");
Console.WriteLine($" Full path: {Path.GetFullPath(path)}");
Console.WriteLine();
}
}
// The example displays the following output when run on a Windows system:
// Path: C:Documents
// Rooted: True
// Fully qualified: False
// Full path: c:\Users\user1\Documents\projects\path\ispathrooted\Documents
//
// Path: /Documents
// Rooted: True
// Fully qualified: False
// Full path: c:\Documents
//
// Path: C:/Documents
// Rooted: True
// Fully qualified: True
// Full path: C:\Documents
Path.Combine Method的更多相关文章
- [原]System.IO.Path.Combine 路径合并
使用 ILSpy 工具查看了 System.IO.Path 类中的 Combine 方法 对它的功能有点不放心,原方法实现如下: // System.IO.Path /// <summary&g ...
- 关于程序路径Path.Combine以及AppDomain.CurrentDomain.BaseDirectory
关于程序路径 LucenePath:@(System.Configuration.ConfigurationManager.AppSettings["LucenePath"])&l ...
- C# Path.Combine 方法的用法
C# Path.Combine 方法的用法 *.注意: string filePath3= Path.Combine(string path1,string path2): 情况一: path2中 ...
- Path.Combine 合并两个路径字符串,会出现的问题
Path.Combine(path1,path2) 1.如果path2字符串,以 \ 或 / 开头,则直接返回 path2
- 基于用Path.Combine的优化
Path.Combine: 什么时候会用到Path.Combine呢?,当然是连接路径字符串的时候! 所以下面的代码可以完美的工作: public static void Main() { strin ...
- 使用System.IO.Combine(string path1, string path2, string path3)四个参数的重载函数提示`System.IO.Path.Combine(string, string, string, string)' is inaccessible due to its protection level
今天用Unity5.5.1开发提取Assets目录的模块,使用时采用System.IO.Path.Combine(string, string, string, string)函数进行路径生成 明明是 ...
- c# Path.Combine
Path.Combine: c#获取当前项目路径 : //获取包含当前执行的代码的程序集的加载文件的完整路径 var appPath = System.IO.Path.GetDirectoryName ...
- Path.Combine(
// 获取程序的基目录. var dir1 = System.AppDomain.CurrentDomain.BaseDirectory; // 获取模块的完整路径. var dir2 = Syste ...
- C# Path.Combine 缺陷(http路径用Uri类)
Path.Combine: 什么时候会用到Path.Combine呢?,当然是连接路径字符串的时候! 所以下面的代码可以完美的工作: public static void Main() { strin ...
随机推荐
- Flutter——FloatingActionButton组件(浮动按钮组件)
FloatingActionButton 简称 FAB ,可以实现浮动按钮,也可以实现类似闲鱼 app 的地步凸起导航. 属性名称 属性值 child 子视图,一般为 Icon,不推荐使用文字 ...
- [networking][sdn] BGP/EGP/IGP是什么
引子 这是一个惊悚的故事,胆小的人不要点开.整个故事,是从这张图开始的. 整个图,分左中右三块.左边是tom和他所在的网络.右边是jerry和他所在的网络.这两个网络可以在世界上的任何一个角落.彼此有 ...
- Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...
- Paper Reading:Deep Neural Networks for YouTube Recommendations
论文:Deep Neural Networks for YouTube Recommendations 发表时间:2016 发表作者:(Google)Paul Covington, Jay Adams ...
- reverse函数的实现
用递归的方法实现字符串的倒叙 #include <string.h> void reverse_my(char *a,int len) { int tmp;//中间值 if(len < ...
- ASP.NET MVC 入门7、Hellper与数据的提交与绑定
View视图 我们可以手写HTML代码, 也可以采用基类提供的Helper类完成HTM代码. 示例: <%=Html.ActionLink("首页","index& ...
- HaspMap和ConcurrentHashMap
参考自:http://www.importnew.com/28263.html HaspMap和ConcurrentHashMap(康科瑞特哈希迈普) Java7 HashMap 不支持并发操作,Ha ...
- python - scrapy 爬虫框架 ( redis去重 )
1. 使用内置,并加以修改 ( 自定义 redis 存储的 keys ) settings 配置 # ############### scrapy redis连接 ################# ...
- 【CSP模拟赛】God knows (李超线段树)
题面 CODE 稍微分析一下,发现把(i,pi)(i,p_i)(i,pi)看做二维数点,就是求极长上升子序列的权值最小值. 直接李超线段树 #include <bits/stdc++.h> ...
- 判断大文件是否上传成功(一个大文件上传到ftp,判断是否上传完成)
大文件上传ftp,不知道有没有上传完成,如果没有上传完成另一个程序去下载这个文件,导致下载不完整. 判断一个文件是否上传完成的方法: /** * 间隔一段时间去计算文件的长度来判断文件是否写入完成 * ...