Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried to write in cmd this as is:
"C:\Program Files\WinRAR\Rar.exe" a C:\Users\User\Desktop\temp.zip "C:\Users\User\Desktop\img"
but using this code:
C#
Console( '"' + path_to_winrar + '"' +  " a " + dest + " " + '"' +source +'"');

I got
"\"C:\\Program Files\\WinRAR\\Rar.exe\" a C:\\Users\\User\\Desktop\\18.12.2012.zip \"C:\\Users\\User\\Desktop\\img\\\""
How?
Posted
Updated 18-Dec-12 9:48am
v2
Comments
Richard C Bishop 18-Dec-12 15:54pm    
The backslash is an escape character by itself. So, when using it in a string value it must be doubled up. Adding "@" in front of a string like that will prevent you from having to use two backslashes.

You can use \" or if you put a @ at the front of the string, use "".

as in string s = @"this is in ""quotes"", OK ? ";
 
Share this answer
 
v2
The string is correct but you have been confused by the debugger display which inserts escape characters.

Dump your string to the console and you'll see that it's ok.

Try
C#
string s = '"' + "hello" + '"' + " " + '"' + "!" + '"';
Console.WriteLine(s);


The Console will show
"hello" "!"

and the debugger will show
"\"hello\" \"!\""

Alan.
 
Share this answer
 
Hi,
Try this,
C#
string path_to_winrar = @"C:\Program Files\WinRAR\Rar.exe";
string dest = @"C:\Users\User\Desktop\temp.zip";
string source = @"C:\Users\User\Desktop\img";
string result = string.Format("\"{0}\" a {1} \"{2}\"", path_to_winrar, dest, source);


I hope this will help.
Thanks :)
 
Share this answer
 
Comments
lewax00 18-Dec-12 19:19pm    
I prefer using String.Format for this type of thing myself, it seems a bit easier to read. +5
Sk. Tajbir 19-Dec-12 2:06am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900