답변:
아무도 내가 여기에서 대답하지 못했기 때문에 내 문제를 해결하고이 작업을 조사 할 것입니다. 당신이 무슨 생각을하는지 제게 알려주세요
의사 코드
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
암호:
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);
}