Windows – How to verify two copied files are exactly the same in Windows

hashingwindowswindows 7

I’m doing a backup on my Samsung rv420 running Windows 7 Home Starter Edition.

In order to do it, I want to ensure that when making a copy from my computer to a external device, the files being copied do not change in the slightest. For that, I’ll do the next: I’ll take a file from my computer, copy it in the external device, and then copy it again from the external device to the computer. So the file has “traveled” trought the device, and I want to know if it's changed or not.

I know little abut hash functions. I have a program called FileMenu Tools that includes a function for calculating a couple of different hash algorithms. I hope the program does it job properly.

I did what I described with a file, I, logically, ended with two files, original and a copy I left in the desktop. I calculated the hash function and it wasn’t the same.

I don't know why is this. The hash varies upon in which directory is located a file?

What can you recommend me to achieve what I want, which is checking a file is exactly the same after traveling trought external device?

Best Answer

A native solution to Windows (without downloading third party) is to use some powershell commands.

Open powershell.exe (either as user or admin). Then, use the following command.

Compare-Object "$(Get-Content $PATH1)" "$(Get-Content $PATH2)"

You can set $PATH1 and $PATH2 to your file paths and copy paste the command above.

If it returns nothing, the files are identical in content, which is what I believe you want. Note that this command does not check for identical permissions, identical modified date, etc. To compare identical modified date and mode, use the following command.

Compare-Object "$(Get-ItemProperty $PATH1 | Select-Object Mode, LastWriteTime)" "$(Get-ItemProperty $PATH2 | Select-Object Mode, LastWriteTime)"

To compare the permission, use the following command.

Compare-Object "$(Get-Acl $PATH1).Access" "$(Get-Acl $PATH2).Access"

Again, you can set $PATH1 and $PATH2 and just copy and paste the commands above.

In all three commands, if it returns something, you know that they are not the same. On the other hand, if it returns nothing, you know that they are exactly the same in content (1st command), last write time and mode (2nd command), and permissions (3rd command).