I'm trying to pass an argument to a process a folder with space in its name. It doesn't recognize the folder. How can i do that?
string my_arg = @"C:\\program files\\my folder with spaces";
ProcessStartInfo proc = new ProcessStartInfo();
proc.FileName = @"C:\batches\my_batch.bat";
proc.Arguments = @my_arg ;
Process.Start(proc);
the process wont start - it does work if i use a folder with no spaces in the name. Thank you!
You’re using literal strings; there is no need to escape the backslashes, and indeed if you do then there’s no need to use a literal string in the first place.
The spaces on the other hand require special care – encase the argument into quotes solves this.
string my_arg = @"""C:\program files\my folder with spaces""";
try this:
string my_arg = "\"C:\\program files\\my folder with spaces\"";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With