How to compare two files by content, in Windows

There are times when you need to compare two files and check whether their content is different. In some situations, you could just open the two files and look through their contents, like when you want to compare two pictures or two text files. However, that's a rather tedious task to perform, and you might miss small differences, like a slight change in tint on a photo, or a phrase in a text file. That's why it is good to know a few methods to programmatically compare the contents of two files, using software instead of your senses. :) Here are three ways in which you can do that, using PowerShell or third-party apps for Windows:

How to compare two files using PowerShell

Windows 10 doesn't have a built-in tool for comparing two files. However, you can use PowerShell to do so. Start by opening PowerShell: a quick way to do it is to press the Win + X keys on your keyboard simultaneously, and then press I if you want to run PowerShell as a standard user, or A if you want to run it as an administrator.

Once you've opened PowerShell run the following command:

if((Get-FileHash "Path to the first file").hash -eq (Get-FileHash "Path to the second file").hash) {"The two compared files are identical"} else {"The two compared files are NOT identical"}

Of course, you should change "Path to the first file" and "Path to the second file" with the real paths to your files. For example, we wanted to compare two files called DigitalCitizen1.txt and DigitalCitizen2.txt, both found on our D: drive.

The two files that we wanted to compare by contents

To compare their contents, we had to run this command:

if((Get-FileHash "D:\DigitalCitizen1.txt").hash -eq (Get-FileHash "D:\DigitalCitizen2.txt").hash) {"The two compared files are identical"} else {"The two compared files are NOT identical"}

Running the file compare command in PowerShell

If the content of the two files is the same, the output you get in PowerShell tells you that "The two compared files are identical."

The output you get in PowerShell when the two files are the same

If the contents of the two files are different, the output you get in PowerShell tells you that "The two compared files are NOT identical."

The output you get in PowerShell when the files are different

Although using PowerShell is both fast and fairly easy, some people do not like using command-line environments. Because of that, we're also going to show you how to compare two files in Windows using third-party apps that offer graphical user interfaces.

How to compare two files using Total Commander

Total Commander is a shareware file manager that is available for all Windows versions. You can get it from its official website, here: Total Commander. Once you've installed and opened it, use its windows to navigate to the two files that you want to compare. In the left side of Total Commander, navigate to the first file, and on the right, navigate to the second file. Then, select the two files by clicking on them and then pressing the spacebar. When the files are selected, their name is colored in red, as you can see in the screenshot below.

Selecting the two files to compare, in Total Commander

Now open the Files options from Total Commander's menu, on the top-left corner, and click on "Compare By Content."

Asking Total Commander to Compare By Content the two files

If the two files that you chose to compare are identical, Total Commander opens a small popup window in which it tells you that "The two files have the same content!".

The message you get from Total Commander when the two files are the same

If the contents of the two compared files differ, Total Commander opens a window in which it shows you the differences between the two files, highlighted in red.

The Compare contents shown by Total Commander when the two files are different

Total Commander also gives you other options for checking the differences and editing the two files, but they are out of the scope of this tutorial, so we're letting you discover them on your own.

How to compare two files using AptDiff

A freeware app that can help you compare files by contents is AptDiff. Although the app is not maintained anymore, it still works in all Windows versions from Windows 2000 and up, including Windows 10. You can get it from Softpedia.

After you install and open AptDiff, it immediately asks you to select the files that you want to compare. Enter the paths to the two files or use the "…" buttons to browse through your computer and select them.

Using AptDiff to choose the two files to be compared

Then choose whether you want to compare the two files as text files, or if you prefer to compare them on a binary level. You can choose any option, regardless of the type of files that you compare. However, know that once the contents of the files are compared, the app loads their contents in two separate panes and shows you the differences identified, if any. If you choose to "Compare as Text," the two panes show the text contents and differences. Otherwise, if you choose to "Compare as Binary," the contents of the two files are shown in hexadecimal code.

AptDiff shows the differences between the two compared files

Just like Total Commander, AptDiff also lets you use additional tools for comparing and editing the contents of the two files.

What is your favorite way of comparing two files by content?

Now you know three easy ways of comparing two files by content in Windows. Which of them is your favorite? Do you prefer using commands in PowerShell, or would you rather install and use a third-party app that also has a visual interface? If you know other methods to compare files, let us know by leaving a comment in the section below.