Directory Copy:
Purpose:
To create the ability to copy directory’s across multiple servers. E.g. copy directory A from Server: 1 to directory B on server 2.
When copying the directory’s you will only want to copy across new and changed files and for the changed files to overwrite any files on Server: 2
Another possibility is that you do not want to copy all files/directories but exclude certain files.
Code:
2 different ways of doing this 1 being the Clean purely .net way and the other and the one that I have chosen is a legacy dos command within a VB class and form.
Using ROBOCOPY we are reducing the amount of code needed whilst having the complex features that we require for this purpose.
First thing that I do is to turn on

Option Strict and Option Explicit On

We then need to import any libraries that we are going to use which are:

So what’s happening above is that the class is passed its x and y parameters which in my case is going to be ("ROBOCOPY", """Directory 1""Directory 2"" /MIR /XF .Config ")

The /MIR and /XF are the switches for Robocopy. /MIR is the command that copies the directory and overwrites any files that are needed.
The /XF is the exclude command and in my case it is excluding and .config files.

Obviously we will need to have the program us create an output so we can see what it has done and that is what we have written above with the code that RedirectStandardOutput = True is doing.
So if you were to put a break point on the line

Console.WriteLine(sOutput)

and run your program you can see what it has done i.e if it has copied the data or if it hasn’t liked your parameters.

So that’s it a quick way to create a simple Directory Copy Program with limited amount of coding using DOS.

The other options instead of the Legacy Dos option i have provided are:

the framework way or just looping through all the files in the directory