68 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Configuration;
namespace ConsolePublishReportUnica
{
public class Program
{
public static string _sourcePath =ConfigurationManager.AppSettings["pathSource"];// "\\vmbfwsrepsei01c.fideuram.bancafideuram.it\d$\Consulenza.Unica.Services";
public static string _targetPath1 = ConfigurationManager.AppSettings["pathTarget1"];
public static string _targetPath2 = ConfigurationManager.AppSettings["pathTarget2"];
static void Main()
{
// Copy from the current directory, include subdirectories.
DirectoryCopy(_sourcePath, _targetPath1, true);
if (ConfigurationManager.AppSettings["existSecondTarget"] == "1" && _targetPath2 != "")
DirectoryCopy(_sourcePath, _targetPath2, true);
}
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}
DirectoryInfo[] dirs = dir.GetDirectories();
// If the destination directory doesn't exist, create it.
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string temppath="";
if (file.Name.ToLower() != "web.config")
{
temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, true);
}
}
// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
string temppath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
}
}
}