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");
4
  • Check your 'destPath' Commented Jul 26, 2016 at 5:26
  • now issue is solve i would to like to thanks Mostafiz :) Thanku Commented Jul 26, 2016 at 5:31
  • Be a professional and do things properly. A C# programmer DOES NOT shell to batch files. Here is the MSDN sample msdn.microsoft.com/en-us/library/cc148994(v=vs.100).aspx Commented Jul 26, 2016 at 5:39
  • ok great, first try to find a same question and solution in here, if no found anything then asks a question :0 Commented Jul 26, 2016 at 5:45

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.