1

I want to execute batch files one by one so on console if I press yes then next file should execute if I press no then console is ended

string file = @"C:\Users\HP\Desktop\Date";
ProcessStartInfo ProcessInfo;  
foreach (string c in Directory.EnumerateFiles(file))
{
    Process p = new Process();
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.FileName = c;
    p.Start();
    p.WaitForExit();
}
CozyAzure
  • 8,280
  • 7
  • 34
  • 52
  • possible duplicate https://stackoverflow.com/questions/5519328/executing-batch-file-in-c-sharp – Hameed Syed Jul 20 '17 at 06:35
  • Possible duplicate of [Executing Batch File in C#](https://stackoverflow.com/questions/5519328/executing-batch-file-in-c-sharp) – Max Play Jul 20 '17 at 06:50

2 Answers2

0

You want to do like as follows and Use Windows Form

string file = @"C:\Users\HP\Desktop\Date";
ProcessStartInfo ProcessInfo;  
foreach (string c in Directory.EnumerateFiles(file))
{
    if (MessageBox.Show("Are you sure?",
                        MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
        Process p = new Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.FileName = c;
        p.Start();
        p.WaitForExit();
    }
}
Sourabh Somani
  • 2,138
  • 1
  • 13
  • 27
0
ConsoleKeyInfo key ;
while(true) //your loop condition
{
    key = Console.ReadKey(true);
    if(key.Key == ConsoleKey.Y)
    {
        //Do your stuff
    }
    else
    {
        break;
    }
}

Hope this help

Nino
  • 6,931
  • 2
  • 27
  • 42