0

I create one window application and as per user selection i create one batch file for copy files in one directory to another directory file is created but its not execute i don't know why? please help.

in code i user process class to execute batch file but its through exception at proc.start();
My code is:

            Process proc = null;
            string tempPath = @"C:\Users\jsolanki\Desktop\temp.bat";
            StreamWriter sw = new StreamWriter(tempPath);
            StringBuilder content = new StringBuilder();
            foreach (string item in tempList)
            {
                content.Append(string.Format("Copy \"{0}\"  \"{1}\\\" \r\n", item, destPath));

            }

            sw.WriteLine(content);
            sw.Close();

            string batDir = tempPath;
            proc = new Process();
            proc.StartInfo.WorkingDirectory = batDir;
            proc.StartInfo.FileName = "temp.bat";
            proc.StartInfo.CreateNoWindow = false;
            proc.Start();
            proc.WaitForExit();
            MessageBox.Show("Copy is Complete");
Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319
Jasmin Solanki
  • 319
  • 6
  • 19

1 Answers1

0
string tempPath = @"C:\Users\jsolanki\Desktop\temp.bat";
string batDir = tempPath;
proc.StartInfo.WorkingDirectory = batDir;

Check carefully you have set working directory a file and not a directory.

Also print the exception message.

The Shooter
  • 733
  • 3
  • 9