-2

When using a break point the root string contains the path with double backslash when I copy this complete path and try to get to it in the File Explorer the path can't be found. But if manual I remove one backslash from each part of the path so the whole path will be with one backslash instead two then it will find the path in the File Explorer. This is the problem in the code. I'm getting exception that the path can't be found but only because the path string is built for some reason with double back slash :

root

Then it's getting to a catch and there when I'm clicking on the small Message small magnifying glass I see the same root string but with one backslash. So I'm confuse why first in the break point it's with two backslash and in the catch with one backslash ? And how can I fix it so it will find the path with double backslash or with one only ?

The Message in the catch part same root string but with one backslash

I tried to add in the code this line :

Path.GetFullPath(root).Replace(@"\\", @"\");

but it didn't change anything. Still, in the break point it's with two backslashes.

And most of the root paths are fine, but at some points, it's getting to the path in the screenshots and it's not finding this path because it's with two backslashes, but the path does exist and other paths are fine, so I can't figure out why this specific path can't be with two backslashes?

What should I do in this case/s ?

I also saw in some answers and solutions that doing this replace Replace(@"\\", @"\"); is not so good because some path's might be in the format E:\\test\test1\test2, which is a mix of two and one backslash.

zx485
  • 28,498
  • 28
  • 50
  • 59
yaron bechar
  • 31
  • 1
  • 6
  • I did not count the characters (I could if you had posted as text, not as image!), but maybe you hit the [260 character limit](https://stackoverflow.com/questions/1880321/why-does-the-260-character-path-length-limit-exist-in-windows)? – Klaus Gütter May 25 '20 at 04:45
  • Does this answer your question? [Why does .NET add an additional slash to the already existent slashes in a path?](https://stackoverflow.com/questions/5465923/why-does-net-add-an-additional-slash-to-the-already-existent-slashes-in-a-path) – Jim G. Mar 12 '23 at 18:09

1 Answers1

0

When the breakpoint hits, it will show you the coding string representation, which will always show you a double backslash, which will always represent a single backslash; this is called an escape character:

"\\" = \ // normal string representation
@"\" = \ // With the @ symbol, you only have to put down one backslash

Examples:

"\n" // Represents a new line
"\"" // Represents the quote character (")
"\u0031" // In debugging, will show you either "\u0031" or "1", but visually will show you 1
"\"quotes\"" // In debugging, will show you "\"quotes\"", but visually will show you "quotes"

You can find some more examples of escaped characters here.

In the second picture in your question, it only shows one backslash because it is the actual character (debugging shows you "\\", visually shows you \).

JJtheJJpro
  • 81
  • 3
  • 7