How can I launch a folder whose name contains a comma, using ProcessStartInfo in C#?
I have an app that queries a database for the location of a nested folder used for a task, and opens this folder (using the ProcessStartInfo
class to launch explorer.exe
and pass in the folder name as an argument).
This works fine except for a number of folders that contain commas (and unfortunately there are a load of them!)
Say, for a folder called C:\this,folder\
, it tries to launch "folder". How can I get it to treat the comma as verbatim?
Sample code:
public void LaunchExplorer() {
ProcessStartInfo explorer = new ProcessStartInfo();
string windir = Environment.GetEnvironmentVariable("WINDIR");
System.Diagnostics.Process prc = new System.Diagnostics.Process();
prc.StartInfo.FileName = windir + @"\explorer.exe ";
prc.StartInfo.Arguments = @"c:\this,folder";
prc.StartInfo.UseShellExecute = false;
try
{ 开发者_JS百科
prc.Start();
}
catch
{
MessageBox.Show("cannot open folder " + prc.StartInfo.Arguments);
}
}
Have you tried enclosing the folder name in quotes, like this?
prc.StartInfo.Arguments = "\"c:\\this,folder\"";
prc.StartInfo.Arguments = "\"c:\\this,folder\"";
will do the trick
精彩评论