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()) foreach (var file in sourceDir.GetFiles())
{ {
string destinationFile = Path.Combine(desDir.FullName, file.Name); string destinationFile = Path.Combine(desDir.FullName, file.Name);
file.CopyTo(destinationFile, true); if (File.Exists(destinationFile))
{
Console.WriteLine($"{file} CopyTo--> {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);
}
} }
} }
catch (Exception ex) catch (Exception ex)

View File

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