【发布时间】:2011-03-08 08:43:20
【问题描述】:
我有一个应用程序查询数据库中用于任务的嵌套文件夹的位置,然后打开该文件夹(使用 ProcessStartInfo 类启动 explorer.exe 并将文件夹名称作为参数传递)。
这很好用,除了一些包含逗号的文件夹(不幸的是它们有很多!)
比如说,对于一个名为C:\this,folder\ 的文件夹,它会尝试启动“文件夹”。我怎样才能让它将逗号逐字处理?
示例代码:
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
{
prc.Start();
}
catch
{
MessageBox.Show("cannot open folder " + prc.StartInfo.Arguments);
}
}
【问题讨论】:
-
也许用引号括起来 (
"c:\this,folder")? -
explorer 警告您“文件夹”文件夹不存在 - 它将逗号视为前导逗号,即尝试打开“文件夹”而不是“c:\this,folder”跨度>
标签: c# explorer processstartinfo