什么是检查的路径是UNC路径或本地路径的正确方法? [英] What is the correct way to check if a path is an UNC path or a local path?

查看:316
本文介绍了什么是检查的路径是UNC路径或本地路径的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要检查的路径是一个UNC路径的最简单的方法当然是检查的完整路径的第一个字符是字母或反斜线。这是一个很好的解决方案,或可能有问题的呢?

The easiest way to check if a path is an UNC path is of course to check if the first character in the full path is a letter or backslash. Is this a good solution or could there be problems with it?

我的具体问题是,我想创建一个System.IO.DriveInfo对象,如果有在路径中的一个驱动器号。

My specific problem is that I want to create an System.IO.DriveInfo-object if there is a drive letter in the path.

推荐答案

由于路径没有在第一和第二位置两个反斜杠,通过definiton,而不是一个UNC路径,这是一种安全的方式来进行确定。

Since a path without two backslashes in the first and second positions is, by definiton, not a UNC path, this is a safe way to make this determination.

在第一位置的驱动器盘符(C :)是植根本地路径。

A path with a drive letter in the first position (c:) is a rooted local path.

既没有这个事情(MyFolder的\等等)的路径是相对本地路径。这包括只有一个单一的斜杠的路径(\ MyFolder的\等等)。

A path without either of this things (myfolder\blah) is a relative local path. This includes a path with only a single slash (\myfolder\blah).

这篇关于什么是检查的路径是UNC路径或本地路径的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆