Copy files using a runtime created batch file C#

If you would like to copy one or several files using a batch file. The command for that is “copy {target} {destination}”. It’s also possible to use wildcards i.e “copy *.txt c:\temp”.
To create a bat (batch) file on runtime and then execute the file you could write something like this in C#.


string batchFileName = @"C:\{filePath}\copy.bat";
System.IO.File.WriteAllText(batFileName, @"copy {fileName}.{extension} {destination-filePath}");
System.Diagnostics.Process.Start(batFileName);