tags:

views:

335

answers:

3

How does C# cope with file separators? Is it always assumed the file separator is "\" (or "\\" and does this have to be escaped like this?

+13  A: 

I think Path.DirectorySeparatorChar is what you need. You can find it in the System.IO namespace.

Geo
Sorry for pointing to PathSeparator, I fixed it now.
Geo
+5  A: 

To combine paths use, and as suggested by Geo, this works in conjunction with DirectorySeparatorChar

IO.Path.Combine("path", "file.ext");
Yannick M.
+1  A: 

If by file separators, you really mean directory separators, then you need Path.DirectorySeparatorChar and Path.AltDirectorySeparatorChar.

These will get the relevant platform-specific characters, without having to hard-code them (and also avoiding the need to escape them properly).

adrianbanks