Delete file Cmd and C #

advertisements

I'm trying to make an updater in C# and I want to delete the updater once it's done.
So I have this code in C#:

var path = Environment.CurrentDirectory + "\\WindowsFormsApplication1.exe";
Process.Start("cmd.exe /c del " + path);

But I get this error message:

Win32Exception was unhandled
The system cannot find the file specified

But I'm sure the path is spelled right, so I don't think that's the problem.

Any ideas?


var path = Environment.CurrentDirectory + "\\WindowsFormsApplication1.exe";

Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = string.Format("/c del \"{0}\"", path);
process.Start();

Or

Process.Start("cmd.exe", string.Format("/c del \"{0}", path));