https://docs.microsoft.com/en-us/dotnet/api/system.io.path.combine?view=netframework-4.8#System_IO_Path_Combine_System_String_System_String_

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的更多相关文章

  1. [原]System.IO.Path.Combine 路径合并

    使用 ILSpy 工具查看了 System.IO.Path 类中的 Combine 方法 对它的功能有点不放心,原方法实现如下: // System.IO.Path /// <summary&g ...

  2. 关于程序路径Path.Combine以及AppDomain.CurrentDomain.BaseDirectory

    关于程序路径 LucenePath:@(System.Configuration.ConfigurationManager.AppSettings["LucenePath"])&l ...

  3. C# Path.Combine 方法的用法

    C#   Path.Combine 方法的用法 *.注意: string filePath3= Path.Combine(string path1,string path2): 情况一: path2中 ...

  4. Path.Combine 合并两个路径字符串,会出现的问题

    Path.Combine(path1,path2) 1.如果path2字符串,以 \ 或 / 开头,则直接返回 path2

  5. 基于用Path.Combine的优化

    Path.Combine: 什么时候会用到Path.Combine呢?,当然是连接路径字符串的时候! 所以下面的代码可以完美的工作: public static void Main() { strin ...

  6. 使用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)函数进行路径生成 明明是 ...

  7. c# Path.Combine

    Path.Combine: c#获取当前项目路径 : //获取包含当前执行的代码的程序集的加载文件的完整路径 var appPath = System.IO.Path.GetDirectoryName ...

  8. Path.Combine(

    // 获取程序的基目录. var dir1 = System.AppDomain.CurrentDomain.BaseDirectory; // 获取模块的完整路径. var dir2 = Syste ...

  9. C# Path.Combine 缺陷(http路径用Uri类)

    Path.Combine: 什么时候会用到Path.Combine呢?,当然是连接路径字符串的时候! 所以下面的代码可以完美的工作: public static void Main() { strin ...

随机推荐

  1. 【robotframework】robotframework环境搭建

    一.基于python3.6环境 在dos命令输入 pip install robotframework 在线安装robotframework在dos命令输入 pip install Pypubsub= ...

  2. JS知识体系【JQ】附加理论+视频地址铺助学习

    理论部分:https://www.jianshu.com/p/e10792076c6e  //不吃鱼的猫_8e95---简书平台 https://www.cnblogs.com/hongqin/p/5 ...

  3. 常见的linux上的服务重启脚本

    手写linux上的重启脚本,先把提纲列下 1.检查进程是否存在 存在杀死 2.备份原来的包到指定目录 3. 拉取新包,我这边为了简便,没有从jenkins slave上拿 4.启动命令 5.检查是否进 ...

  4. python函数式编程-匿名函数

    >>> map(lambda x: x * x, [, , , , , , , , ]) [, , , , , , , , ] 关键字lambda表示匿名函数,冒号前面的x表示函数参 ...

  5. IDEA实用教程(三)

    4. JDK环境的配置 1) 进入JDK配置界面 2) 创建JDK环境 3) 选择本地JDK的安装位置 4) 保存配置 点击右下角的Apply后,再点击OK保存配置

  6. Java stackoverflowerror异常与outofmemoryerror异常区别

    1.stackoverflow: 每当java程序启动一个新的线程时,java虚拟机会为他分配一个栈,java栈以帧为单位保持线程运行状态:当线程调用一个方法是,jvm压入一个新的栈帧到这个线程的栈中 ...

  7. Vue中在组件销毁时清除定时器(setInterval)

    在mounted中创建并执行定时器,然后在beforeDestroy或者destroyed中清除定时器 <template> <div class="about" ...

  8. java中创建对象的方式

    Java中有5种创建对象的方式,下面给出它们的例子还有它们的字节码 使用new关键字 } → 调用了构造函数 使用Class类的newInstance方法 } → 调用了构造函数 使用Construc ...

  9. fsLayuiPlugin入门使用

    简介 源码下载后,不能直接打开,必须运行在容器下,例如:nginx.tomcat.jetty等容器. 源码中默认配置了nginx容器,可以直接启动nginx访问. 本文主要介绍下载源码后的使用,避免在 ...

  10. VMWARE许可文件

    VMware 14 Pro 永久许可证激活密钥FF31K-AHZD1-H8ETZ-8WWEZ-WUUVACV7T2-6WY5Q-48EWP-ZXY7X-QGUWD