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

最新文章

  1. python-切片 迭代 生成器
  2. 2015ACM/ICPC亚洲区长春站
  3. Font Awesome图标库
  4. XMPP客户端开发(2)--发送接收消息
  5. iOS中多线程原理与runloop介绍
  6. MyBatis增删改查
  7. Ruby Scripting - Array
  8. 支持 IE8 IE11 和 FF, Chrome 浏览器的圆角
  9. Hibernate4.1.4配置二级缓存EHCache步骤
  10. Cube Stacking(并差集深度+结点个数)
  11. [原创] JavaScript实现简单的颜色类标签云
  12. 201521123084 《Java程序设计》第10周学习总结
  13. 201521123020 《Java程序设计》第6周学习总结
  14. mac 上格式化磁盘出现MediaKit报告设备上的空间不足以执行请求的解决办法
  15. 微信公众号使用LocalStorage解决返回缓存问题
  16. 全网最详细的大数据集群环境下多个不同版本的Cloudera Hue之间的界面对比(图文详解)
  17. OpenStack 图形化服务 Horizon介绍和部署(十二)
  18. 由一次 symbol lookup error 引发的思考
  19. Git 执行更改
  20. Throwable vs Exception

热门文章

  1. rabbitmq笔记(一)rabbitmq简介及基础
  2. PHP经典面试题01
  3. 15 Windows编程——系统内置窗口子类型之button
  4. Nginx的平滑升级记录---适用于编译安装的Nginx
  5. RT-Thread--内存管理
  6. LB_Kim
  7. docker 运行没有权限执行文件解决
  8. Windows下无法新建文件夹
  9. Notepad++ 连接远程 NppFTP
  10. Linux添加shell(.sh)脚本并添加定时任务