Check File Length

This commit is contained in:
ZtRXR 2023-10-01 18:56:34 +08:00
parent b418903e99
commit 2d08e4d8e9
2 changed files with 20 additions and 4 deletions

View File

@ -28,9 +28,25 @@ public class FileCopy
foreach (var file in sourceDir.GetFiles())
{
string destinationFile = Path.Combine(desDir.FullName, file.Name);
file.CopyTo(destinationFile, true);
if (File.Exists(destinationFile))
{
var desFileInfo = new FileInfo(destinationFile);
if (desFileInfo.Length != file.Length)
{
Console.WriteLine($"Renew {file} --> {destinationFile}");
file.CopyTo(destinationFile, true);
}
else
{
Console.WriteLine($"Same {file} --> {destinationFile}");
}
}
else
{
Console.WriteLine($"NewFile {file} --> {destinationFile}");
file.CopyTo(destinationFile, true);
}
Console.WriteLine($"{file} CopyTo--> {destinationFile}");
}
}
catch (Exception ex)

View File

@ -33,7 +33,7 @@ managementEventWatcher.EventArrived += (s, e) =>
Directory.CreateDirectory(dPath);
}
FileCopy.Copy(driveName, dPath);
Console.WriteLine("Scaned and waiting ----------------------");
Console.WriteLine("\n--------------Scaned and waiting--------------\n");
};
managementEventWatcher.Start();