简体   繁体   English

“ DriveLetter:SomeDirectory”上的Path.GetFullPath意外行为

[英]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.

相关问题 “Path.GetFullPath”和网络路径 - “Path.GetFullPath” and network paths PowerShell中的奇怪行为:在下标中调用Path.GetFullPath返回相对于外部脚本的路径 - Strange behavior in PowerShell: Invoking Path.GetFullPath in subscripts return paths relative to the outer script 如何使用Path.GetFullPath在c#中获取文件完整路径 - How to get a file full path in c# with Path.GetFullPath Path.GetFullPath没有返回正确的路径 - Path.GetFullPath doesn't return correct path C#结合绝对路径和相对路径,Path.GetFullPath()不一致 - C# combining absolute and relative paths, Path.GetFullPath() inconsistent 调用Path.GetFullPath()时发生System.OutOfMemoryException - System.OutOfMemoryException when calling Path.GetFullPath() Path.GetFullPath函数仅在当前项目中搜索 - Path.GetFullPath Function searches only in Current Project Path.GetFullPath —仅返回最后一个文件夹,文件名和扩展名 - Path.GetFullPath — Return only the last folder, file name and extension Path.GetFullPath在C#中返回错误的路径 - Path.GetFullPath returning wrong path in C# 为什么 Path.GetFullPath 返回带有额外“bin/Debug/netcoreapp3.0”的地址? - Why Path.GetFullPath returns the address with extra "bin/Debug/netcoreapp3.0"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM