The following trivial code is just an example that does not reflect my real scenario.
I have tried it and it did not work.
I want to delete data.txt using Process rather than using File class.
using System;
using System.Diagnostics;
namespace Tester
{
class Program
{
static void Main(string[] args)
{
Process p = new Process();
p.StartInfo.FileName = "cmd";
p.StartInfo.Arguments = "del data.txt";
p.StartInfo.UseShellExecute=false;
p.EnableRaisingEvents = true;
p.Exited += (sender, e) => { Console.WriteLine("Finished"); };
p.Start();
p.WaitForExit();
}
}
}
How to execute del data.txt using Process?
You need to add the “/C” argument to the process.