[英]Path.GetFullPath unexpected behavior on “DriveLetter:SomeDirectory”
I am trying to get whether a directory path is valid or not using the Path
class as suggested in this answer. 我正在尝试使用此答案中建议的
Path
类来获取目录路径是否有效。
However, while I expect Path.GetFullName("C:SomeDirectory")
(without any slashes) to throw an exception, it returns C:\\Windows\\system32\\SomeDirectory
. 但是,尽管我期望
Path.GetFullName("C:SomeDirectory")
(不带任何斜杠)引发异常,但它会返回C:\\Windows\\system32\\SomeDirectory
。
Also, if I write Directory.Create("C:SomeDirectory")
it tries to create the directory again under C:\\Windows\\system32
. 另外,如果我编写
Directory.Create("C:SomeDirectory")
它会尝试再次在C:\\Windows\\system32
下创建目录。
When I try to enter C:drivers
, for example, to address bar in windows explorer I get error Windows cannot find file. Check the spelling and try again.
例如,当我尝试输入
C:drivers
到Windows资源管理器中的地址栏时,出现错误Windows cannot find file. Check the spelling and try again.
Windows cannot find file. Check the spelling and try again.
Command line gives an error on cd C:drivers
, too. 命令行在
cd C:drivers
也给出了错误。
Is this an expected behaviour? 这是预期的行为吗?
Yes, C: just tells it which drive. 是的,C:告诉它哪个驱动器。 The rest of the path must start with root '\\' if you want the path to run from root - otherwise it'll just be appended to the current directory.
如果要从根目录开始运行,则路径的其余部分必须以根目录'\\'开头-否则,它将仅附加到当前目录中。
The Path and Uri methods are very specific about these things. Path和Uri方法在这些方面非常具体。
All Paths are relative to the current working directory - but starting the path with \\ makes it relative to the root (of that drive) - its the same on the command line too 所有路径都相对于当前工作目录-但以\\开头的路径使其相对于该驱动器的根目录-在命令行上也相同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.