0

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.

Command line gives an error on cd C:drivers, too.

Is this an expected behaviour?

Community
  • 1
  • 1
Yusuf Tarık Günaydın
  • 3,016
  • 2
  • 27
  • 41
  • cd to `c:\windows\system32` then try `cd c:drivers`. All will work. Even weirder is that if you eg map the f: drive, then do `cd c:\windows\system32`, `f:`, `cd c:drivers` and `c:` you'll end up in `c:\windows\system32\drivers`. – David Arno Nov 10 '15 at 13:52

1 Answers1

1

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

mp3ferret
  • 1,183
  • 11
  • 16