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

查看:26
本文介绍了检查路径是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.

推荐答案

由于在第一个和第二个位置没有两个反斜杠的路径,根据定义,不是 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.

没有这些东西的路径 (myfolderlah) 是相对本地路径.这包括只有一个斜杠的路径 (myfolderlah).

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

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

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