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);

One comment

Leave a Reply to MikeCancel Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.