Reputation: 1395
I am opening cmd.exe from my application and navigating it to a file but the problem is that if the file path has spaces in it, it won't go there.
Process.Start("cmd.exe", "/C choice /C Y /N /D Y /T 3 & cd C:\Temp Folder");
Instead for looking of Temp Folder, it will only look for temp I guess.
One way is to wrap the path with " " but I can't do it in a string. (tried ' ')
Another way is to loop through the path, find spaces and replace them with something, but I don't know with what.
I could use some help with either of this ways (if you have a better one, that's great)
Upvotes: 0
Views: 2552
Reputation: 49251
You need to use an escape character \
for special characters. So, to escape the " , use \"
Upvotes: 3
Reputation: 108957
The \
in the string needs to be escaped and you need to include folder names with space in double quotes.
Try
Process.Start("cmd.exe", @"/C choice /C Y /N /D Y /T 3 & cd C:\""Temp Folder""");
or
Process.Start("cmd.exe", "/C choice /C Y /N /D Y /T 3 & cd C:\\\"Temp Folder\"");
Upvotes: 4