-1

I want to include batch file into a main file.

//contents of copy.bat

copy *.txt Output.txt

Is there any direct solution using c#. Following code generates no error at the cost of no output.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Diagnostics.Process.Start(@"C:\mydir\copy.bat");

        }
    }
}
Shahgee
  • 3,303
  • 8
  • 49
  • 81
  • 1
    Just a note : simply renaming some .txt file to .xls will not make it valid Excel file – Dimitar Tsonev Nov 18 '15 at 12:10
  • 1
    How can someone who's been here for 4 years and with decent rep say "I don't know anything about C# so can you write all the code for me?". Aaaand... it's been edited out. – Equalsk Nov 18 '15 at 12:12
  • "*Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the [How to Ask page](http://stackoverflow.com/help/how-to-ask) for help clarifying this question.*" – Wai Ha Lee Nov 18 '15 at 12:22
  • Your example does not follow my guideline. You don't have to invoke a *.bat file from C#. Just use C#'s build in APIs. I recommend you doing a basic C# course first ;-) – Fabe Nov 18 '15 at 15:07

1 Answers1

2

C#

Since you a learning, I won't give you a complete sample. It would just kill the learning effect. Problem with the approach is, that you load all contents in memory, which is limited. Just take a look at Streams, if you want to handle the task more efficiently (could be your exercise 2).

.bat

Batch files are really not suitable for such a task. Take a look at PowerShell, if you want to do this as administrative task.

Remark

Get an https://www.pluralsight.com/ account, they have excellent C# courses.

Community
  • 1
  • 1
Fabe
  • 1,185
  • 4
  • 11
  • 22