Replace all if file size identical

It happens that sometimes you might need to replace only identical files in size.
This happens in scenarios where you made copies of entire files and folders, started working on the new directory on a daily basis, making changes in a thousand files but suddenly, you wanna open a CAD file or even a XLS file and you start finding out many of other files got corrupted during the copy process.

If you're lucky enough, you still have the backup and discovered you could have used TeraCopy to avoid it all. But don't worry, TeraCopy's got you covered. You can still overwrite only the files that got corrupted without a hassle.

Just select the root of your OLD backup and paste over the current root. We will find existing files, but as you wish, we will only replace the ones that are identical in size.

I made an implementation in a custom app to do to this using Delphi and GetFileSize function. It happens that even corrupted files have the same size of the origin non corrupt files.

Just an example of the code:

procedure TForm1.CompareFileSizes(Memo1, Memo2: TJvMemo; const BasePath1, BasePath2: string);

var

i: Integer;

FileName, FilePath1, FilePath2: string;

FileSize1, FileSize2: Int64;

begin

for i := 0 to Memo1.Lines.Count - 1 do

begin

FileName := Memo1.Lines[i];

FilePath1 := Memo1.Lines[i]; //TPath.Combine(BasePath1, FileName);

FilePath2 := Memo2.Lines[i];//TPath.Combine(BasePath2, FileName);

if FileExists(FilePath1) and FileExists(FilePath2) then

begin

FileSize1 := GetFileSize(FilePath1);

FileSize2 := GetFileSize(FilePath2);

if (FileSize1 <> -1) and (FileSize2 <> -1) then

begin

if FileSize1 = FileSize2 then begin

memoTamanhoFinal.Lines.Add(FilePath1);

memoTamanhoInicial.Lines.Add(FilePath2);

end

else

//JvMemo3.Lines.Add(FileName + ' has different sizes in both locations.');

end

else

//JvMemo3.Lines.Add('Error obtaining file size for ' + FileName);

end

else

//JvMemo3.Lines.Add(FileName + ' does not exist in one or both locations.');

end;

end;

Please authenticate to join the conversation.

Upvoters
Status

In Review

Board

TeraCopy

Tags

Feature

Date

Almost 2 years ago

Author

Wagner Consani Filho

Subscribe to post

Get notified by email when there are changes.