Skip to main content

How To Check If Two Files Are Identical

Whether you work as a programmer In a busy corporate environment, or just an average user on the PC, sometimes you may have the need to check If two files contain the exact same content. Stating the obvious, you can simply open each one and physically have a look, but If the files are heavily populated, It can be a very time-consuming process. As such, In this tutorial, I will show you how to check If two files are Identical without opening them.

For the purpose of this tutorial and to keep things simple, I will be using a couple of text files throughout the entire article. There are countless reasons why you'd want to compare and verify any differences between a couple of files. Perhaps you've added a line of code In one file, and don't remember If you did the same In the other. Or you want to forward an exact copy to your boss at work, hence want to make sure It matches with that of your own.

Whatever the reason may be, I will show you how It's done, by using the native Windows utility named PowerShell. It Is very accurate with It's comparison- to the point of detecting a difference even when a single comma has been added to a file containing tens of thousands of paragraphs! The process Is extremely simple, so without further delay, let's get this tutorial started.

Step One:

Before I begin, I have two text files (as shown below), that I'll be checking to see If they contain Identical content. They're quite large, thus manually sifting through each one, Is certainly not practical.

Step Two:

Okay, the first thing we need to do, Is access PowerShell. Open the Search bar, enter powershell and click on the search result at the top as shown below.

Step Three:

Next, enter the following command Into PowerShell, replacing C with your drive letter, and Your File Name with the name of both text files that you wish to check.
if((Get-FileHash "C:\Your File Name.txt").hash -eq (Get-FileHash "C:\Your File Name.txt").hash) {"Both Files Are Identical"} else {"Both Files Are NOT Identical"}

In my case, the command Is as follows.
if((Get-FileHash "F:\Windows10Tips1.txt").hash -eq (Get-FileHash "F:\Windows10Tips2.txt").hash) {"Both Files Are Identical"} else {"Both Files Are NOT Identical"}

Your PowerShell window, should look similar to mine. When done, hit Enter on your keyboard.

Step Four:

As you can see, a message of Both Files Are Identical has been returned. Essentially, my files are an exact copy of each other.

Last Step:

Let's test It's accuracy. I've added a single full stop In one of the files, and did not touch any other content. As expected, the difference was detected, confirmed by the message of Both Files Are Not Identical.

Final Thoughts:

I'd say It's safe to assume, that you're quite Impressed with It's accuracy In detecting every minute change In a given file. There are many third-party tools that do a similar job, but there's no need to download anything- namely for the fact that the same result can be achieved natively within Windows.


Popular posts from this blog

Check The Health Of Your Laptop's Battery

When you first purchase your laptop and fully charge the battery thereafter, It runs at It's optimal state for quite a while. However, over time, It Inevitably decreases In performance, and does not hold It's charge capacity as per It's brand new state. This Is due to wear & tear, and a few other factors. It's very Important to know the condition of your battery, so In this tutorial, I will show you how to view the current status and health of your laptop's battery.

Force Windows 10 To Boot To Advanced Startup

In the event your operating system corrupts and losses functionality to some degree, Windows 10 has the Advanced Startup Options menu, that contains a range of diagnostic and repair utilities to help restore the OS back to It's functional state. You can perform a System Restore, Reset your PC, execute commands via the Command Prompt and more. To have It readily available, In this tutorial, I will show you how to force Windows 10 to always boot to the Advanced Startup settings.

How To Troubleshoot Your PC's Power Settings

Upon purchasing your computer with the Windows OS Installed, by default, It's power plan setting Is set to Balanced. Depending on the manufacturer, the hibernate and sleep modes are also configured to turn off at certain Intervals. You can also create a plan of your own, based on your computing usability. Power plan settings can corrupt at the best of times, hence In this tutorial, I will show you how to troubleshoot your PC's power settings natively within Windows.