[英]Path.GetFullPath unexpected behavior on “DriveLetter:SomeDirectory”
我正在尝试使用此答案中建议的Path
类来获取目录路径是否有效。
但是,尽管我期望Path.GetFullName("C:SomeDirectory")
(不带任何斜杠)引发异常,但它会返回C:\\Windows\\system32\\SomeDirectory
。
另外,如果我编写Directory.Create("C:SomeDirectory")
它会尝试再次在C:\\Windows\\system32
下创建目录。
例如,当我尝试输入C:drivers
到Windows资源管理器中的地址栏时,出现错误Windows cannot find file. Check the spelling and try again.
Windows cannot find file. Check the spelling and try again.
命令行在cd C:drivers
也给出了错误。
这是预期的行为吗?
是的,C:告诉它哪个驱动器。 如果要从根目录开始运行,则路径的其余部分必须以根目录'\\'开头-否则,它将仅附加到当前目录中。
Path和Uri方法在这些方面非常具体。
所有路径都相对于当前工作目录-但以\\开头的路径使其相对于该驱动器的根目录-在命令行上也相同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.