| using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading; namespace Xcopy { /// <summary> /// Use This class to Perform Xcopy /// </summary> class Program { /// <summary> /// This is your Main /// </summary> /// <param name="args"></param> static void Main(string[] args) { //Provide the Source location string sourceLoc = @"D:\BackUpFile\"; //Provide your Destination Location string destinationLoc = System.Environment.CurrentDirectory.Remove(System.Environment.CurrentDirectory.IndexOf("bin")) + "Source\\"; string FolderPath = "CopiedFiles"; if (!(Directory.Exists(destinationLoc + @"\" + FolderPath))) Directory.CreateDirectory(destinationLoc + @"\" + FolderPath); //Call a method to perform Xcopy ProcessXcopy(sourceLoc, destinationLoc + @"\" + FolderPath); Console.WriteLine("we are done with the xcopy"); } /// <summary> /// Method to Perform Xcopy to copy files/folders from Source machine to Target Machine /// </summary> /// <param name="SolutionDirectory"></param> /// <param name="TargetDirectory"></param> private static void ProcessXcopy(string SolutionDirectory, string TargetDirectory) { // Use ProcessStartInfo class ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.CreateNoWindow = false; startInfo.UseShellExecute = false; //Give the name as Xcopy startInfo.FileName = "xcopy"; //make the window Hidden startInfo.WindowStyle = ProcessWindowStyle.Hidden; //Send the Source and destination as Arguments to the process startInfo.Arguments = "\"" + SolutionDirectory + "\"" + " " + "\"" + TargetDirectory + "\"" + @" /e /y /I"; try { // Start the process with the info we specified. // Call WaitForExit and then the using statement will close. using (Process exeProcess = Process.Start(startInfo)) { exeProcess.WaitForExit(); } } catch (Exception exp) { throw exp; } } } } |