Like the title says, how do I escape white space passed in a file name to csc.exe? Caret's cannot be used. For example, file path C:\Users\user name\My Documents\file.cs
I would normally do C:\Users\user^ name\My^ Documents\file.cs
but since carets cannot be used, it throws an error. I've tried wrapping the path name in double quotes but no luck. Any help?
-
Very murky when you don't explain exactly how you invoke csc.exe. Support is already built into the .NET framework, best to use it instead of cooking your own. Use CodeDomProvider.CreateProvider("CSharp");– Hans PassantJul 13, 2013 at 11:35
2 Answers
This is a general OS issue, not the compiler.
When you have spaces in a path, you enclose it in "
:
csc <other parameters> "C:\Users\user name\My Documents\file.cs"
The caret character (^) is not recognized as an escape character or delimiter. The character is handled by the command-line parser in the operating system before it is passed to the argv array in the program.
A string enclosed in double quotation marks ("string") is interpreted as a single argument, regardless of white space that is contained within. A quoted string can be embedded in an argument. So as mentioned by Oded enclode it in ".
Reference: http://msdn.microsoft.com/en-us/library/vstudio/78f4aasd.aspx