打开其路径中包含逗号的文件夹

stu*_*ehr 6 .net c#

我需要使用C#通过Windows资源管理器打开文件夹.它工作正常,直到文件夹路径中有逗号.这是一个例子:

System.Diagnostics.Process.Start("explorer.exe", "C:\\folder\\another-folder\\123,456");
Run Code Online (Sandbox Code Playgroud)

错误是:路径'456'不存在或它不是目录.

任何解决方案请:)

Hos*_*Aly 15

尝试在路径周围添加双引号:

System.Diagnostics.Process.Start("explorer.exe", "\"C:\\folder\\another-folder\\123,456\"");
Run Code Online (Sandbox Code Playgroud)

附注:您可能会发现使用逐字字符串文字编写路径更容易,以避免必须转义斜杠:

System.Diagnostics.Process.Start("explorer.exe", @"""C:\folder\another-folder\123,456""");
Run Code Online (Sandbox Code Playgroud)

  • 如果路径包含其他特殊字符(如空格),则还需要执行此操作.因此,为了安全起见,路径字符串应始终加双引号. (2认同)

Tho*_*que 2

尝试用双引号将路径引起来:

System.Diagnostics.Process.Start("explorer.exe", "\"C:\\folder\\another-folder\\123,456\"");
Run Code Online (Sandbox Code Playgroud)