XCOPY C# (edit)
class Program
{
static void Main(string[] args)
{
string[] arr = new[]
{
"Abc/Control.cs"
,"Abc/Def/CustomControl.cs"
};
/*
* XCOPY FOLDER
* --------------------------------------------------
* XCOPY /T /E "D:\Abc\" "D:\BAK\Abc\"
* XCOPY /Y "D:\Abc\Control.cs" "D:\BAK\Abc\"
* --------------------------------------------------
* XCOPY FILE
* XCOPY /T /E "D:\Abc\Def\" "D:\BAK\Abc\Def\"
* XCOPY /Y "D:\Abc\Def\CustomControl.cs" "D:\BAK\Abc\Def\"
*/
string folderSource = @"D:\Abc\";
string folderDestination = @"D:\BAK\Abc\";
foreach (var item in arr)
{
try
{
var fileSourcePath = $"{folderSource}\\{item}".Replace(@"/", @"\").Replace(@"\\", @"\");
var fileDestinationPath = $"{folderDestination}\\{item}".Replace(@"/", @"\").Replace(@"\\", @"\");
var folderSourcePath = Path.GetDirectoryName(fileSourcePath);
var folderDestinationPath = Path.GetDirectoryName(fileDestinationPath);
if (!Directory.Exists(folderDestinationPath))
{
Directory.CreateDirectory(folderDestinationPath);
}
File.Copy(fileSourcePath, fileDestinationPath, true);
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
//throw;
}
}
}
}