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. linux驱动开发随手记【1】

    1.一个patch只完成一项任务 2.用vim编辑多个文件,想同时关闭所有文件时候,可以用 :qall 命令 .vim用户手册08 3.mmc dev 0.mmc为U-boot命令,这句话的含义是设置 ...

  2. ESLint——从零学起

    介绍 ESLint最初是由Nicholas C. Zakas于2013年6月创建的开源项目.它的目标是提供一个插件化的javascript代码检测工具.因此,ESLint就是一个语法规则和代码风格的检 ...

  3. mamcached+(magent+keepalived高可用)搭建及理论概述

    目录 一.理论概述 工作流程 二.部署 环境 环境概述 部署 三.测试 四.总结 一.理论概述 Memcached服务器端与PHP-Memcache客户端安装配置_服务器应用_Linux公社-Linu ...

  4. IP地址简介及Linux网络管理工具

    IP地址简介 IP地址又叫网络地址也称逻辑地址,由32位2进制数组成,分4段每段8位,由10进制数表示,范围0~,段与段之间用点隔开采用点分十进制的表示法,在一个网络中ip地址是唯一的,IP地址最主要 ...

  5. WindowsPE

    什么是WindowsPE Windows Preinstallation Environment(Windows PE),Windows预引导环境,是带有有限服务的最小Win32子系统,基于以保护模式 ...

  6. C++——Big Three(copy ctor、copy op=、dtor)

    Big Three C++ 中Big Three指的是copy ctor 和 copy op=  和  dtor m_data是个字符串指针.一般而言,处理字符串,都是使用指针,在需要存储字符的时候再 ...

  7. Linux用ctrl + r 查找以前(历史)输入的命令

    在Linux系统下一直用上下键查找以前输入的命令,这个找刚输入不久的命令还是很方便的,但是比较久远的命令,用上下键效率就不高了.那个history命令也是个花架子,虽然功能多,但不好用,网上找了下,发 ...

  8. 《AlwaysRun!团队》第四次作业:项目需求调研与分析

     项目  内容  这个作业属于哪个课程 http://www.cnblogs.com/nwnu-daizh/  这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daiz ...

  9. canvas圆形进度条(逆时针)

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...

  10. flask+uwsgi+supervisor部署流程

    背景: 小鱼最近搞了个工程,python用的2.7(用3也可以),后端使用的是flask,服务器用的linux,使用 flask+uwsgi+supervisor部署 ,查阅相关博客.调试.实操,已经 ...