Como ninguém respondeu aqui é a maneira que eu resolvi meu problema e vou pesquisar esta tarefa. Deixe-me saber o que você pensa
pseudo-código
if ((fileA is not in C) and (fileA is not in B))
Copy fileA in B
else if ((fileA is in C) and (fileA is not in B))
if ((Date(FileA) != Date(FileC))
Copy fileA in B
else if ((fileA is not in C) and (fileA is in B))
if ((Date(FileA) != Date(FileB))
Delete(FileB)
Copy fileA in B
else if ((fileA is in C) and (fileA is in B))
if ((Date(FileA) != Date(FileB))
Delete(FileB)
Copy fileA in B
Código:
static void Main(string[] args)
{
string folderA = @"H:\testing_sync\A\";
string folderB = @"H:\testing_sync\B\";
string folderC = @"H:\testing_sync\C\";
string[] files = Directory.EnumerateFiles(folderA, "*.pdf", SearchOption.AllDirectories).ToArray();
DateTime today = System.DateTime.Now;
foreach (var filepath in files)
{
Console.WriteLine(filepath);
string filename = Path.GetFileName(filepath);
Console.WriteLine(filename);
if (!File.Exists(folderC + filename) && !File.Exists(folderB + filename))
{
try
{
Console.WriteLine("first");
File.Copy(folderA + filename, folderB + filename);
Console.WriteLine("Copying " + folderA + filename + " to " + folderB + filename);
Console.WriteLine();
}
catch (Exception ex) { }
}
else if (File.Exists(folderC + filename) && !File.Exists(folderB + filename))
{
try
{
Console.WriteLine("second");
DateTime aModified = System.IO.File.GetLastWriteTime(folderA + filename);
DateTime cModified = System.IO.File.GetLastWriteTime(folderC+ filename);
if (DateTime.Compare(aModified, cModified) != 0)
{
File.Copy(folderA + filename, folderB + filename);
Console.WriteLine("Copying " + folderA + filename + " to " + folderB + filename);
Console.WriteLine();
}
}
catch (Exception ex) { }
}
else if (File.Exists(folderB + filename))
{
try
{
Console.WriteLine("third");
DateTime aModified = System.IO.File.GetLastWriteTime(folderA + filename);
DateTime bModified = System.IO.File.GetLastWriteTime(folderB + filename);
if (DateTime.Compare(aModified, bModified) != 0)
{
File.Delete(folderB + filename);
File.Copy(folderA + filename, folderB + filename);
Console.WriteLine("Copying " + folderA + filename + " to " + folderB + filename);
Console.WriteLine();
}
}
catch (Exception ex) { }
}
/*
DateTime lastModified = System.IO.File.GetLastWriteTime(f);
if (DateTime.Compare(today, lastModified) <= 0)
{
}*/
}
// System.Threading.Thread.Sleep(50000);
}