如何处理文件名

Exp*_*ice 1 c# process c#-4.0

我试图获取可执行文件在内存中运行的位置Application.ExecutablePath并从当前位置删除它,但是我得到了错误The system cannot find the file specified.

据我所知,这是因为路径中的空间.我该如何解决这个问题?这是相关代码:

System.Diagnostics.Process p = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"cmd.exe /C Del " + Path.GetFullPath(Application.ExecutablePath);
p.StartInfo = psi;
p.Start();
Run Code Online (Sandbox Code Playgroud)

M.B*_*ock 6

我更喜欢String.Format简单的字符串连接:

psi.FileName = string.Format("cmd.exe /C Del \"{0}\"",
                              Path.GetFullPath(Application.ExecutablePath));
Run Code Online (Sandbox Code Playgroud)

否则,我相信这也应该有效:

psi.FileName = @"cmd.exe /C Del """ + Path.GetFullPath(Application.ExecutablePath) + """";
Run Code Online (Sandbox Code Playgroud)