I am trying to get whether a directory path is valid or not using the Path
class as suggested in this answer.
However, while I expect Path.GetFullName("C:SomeDirectory")
(without any slashes) to throw an exception, it returns C:\\Windows\\system32\\SomeDirectory
.
Also, if I write Directory.Create("C:SomeDirectory")
it tries to create the directory again under 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.
Windows cannot find file. Check the spelling and try again.
Command line gives an error on cd C:drivers
, too.
Is this an expected behaviour?
Yes, C: just tells it which drive. 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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.