ThisCalculator

Everyday

Compare Files in Two Folders on Windows

Updated · Standard formula, shown below

Compare Files in Two Folders on Windows

To compare files in two folders on Windows, use PowerShell to list each folder’s files and compare their names, sizes, or contents; for a visual side-by-side view, use a dedicated folder-comparison utility. The right method depends on whether you need to find missing files, detect different versions, or verify that file contents match.

Choose what “compare” means

A folder comparison can answer several different questions. Decide what you need before choosing a tool, because matching names do not prove matching contents.

  • Which names are missing? Compare relative paths to find files present in only one folder.
  • Which files have different sizes or dates? Compare metadata for a quick check, knowing it is not a definitive content test.
  • Are the contents identical? Compare file bytes or calculate cryptographic hashes. This is slower, but it checks the actual data.
  • What changed between text files? Use a diff view that highlights added, removed, and changed lines.

Also decide whether subfolders should be included. A comparison of only the top level can miss files nested several folders deep.

Compare folder contents with PowerShell

PowerShell is included with Windows and can compare file paths without installing another program. The following example compares two folders recursively and reports paths that occur in only one of them. Replace the sample paths with your own:

$left = 'C:\Work\FolderA'
$right = 'C:\Work\FolderB'

$a = Get-ChildItem -LiteralPath $left -File -Recurse | ForEach-Object {
    $_.FullName.Substring($left.Length).TrimStart('\')
}
$b = Get-ChildItem -LiteralPath $right -File -Recurse | ForEach-Object {
    $_.FullName.Substring($right.Length).TrimStart('\')
}

Compare-Object -ReferenceObject $a -DifferenceObject $b

Each result has a SideIndicator. <= means the path occurs in the reference list, FolderA; => means it occurs in FolderB. If there is no output, the two lists of relative file paths match. This checks names and folder locations, not file contents.

For a quick, non-recursive comparison, omit -Recurse from both Get-ChildItem commands. For files as well as folders, this example deliberately uses -File; that keeps the comparison focused on files.

Check whether matching files have the same contents

After confirming that paths match, compare the files themselves. One reliable built-in option is Get-FileHash, which calculates a hash for each file. Identical files produce the same hash when the same algorithm is used; a different hash indicates different contents.

For example, calculate a SHA-256 hash for a file with:

Get-FileHash -LiteralPath 'C:\Work\FolderA\report.txt' -Algorithm SHA256

Run the same command for the corresponding file in FolderB and compare the Hash values. To automate this across two full folder trees, first build a mapping between matching relative paths, then calculate and compare hashes for each pair. Hashing reads every file, so it can take time for large folders or files on slow, removable, or network storage.

For two text files, a line-by-line diff is often easier to understand than hashes: a diff can show exactly which lines changed, while a hash only tells you whether the complete files differ. Hashes are useful for checking identity, not for explaining edits.

Use a visual comparison tool

A folder-diff application can display two directory trees side by side, mark files that are unique or different, and often open a separate comparison for text files. This is convenient when you need to review changes before copying anything. Choose a tool that supports recursive comparisons and clearly distinguishes name, size, timestamp, and content comparisons.

Review the application’s comparison settings. Some tools initially use file size and modification time as a quick test, rather than reading every file. That can be appropriate for a fast scan, but it is not equivalent to checking file contents. Treat buttons such as “synchronize,” “mirror,” or “copy” as actions, not comparison results; inspect the proposed direction and changes before applying them.

Command Prompt and metadata checks

Windows Command Prompt’s fc command compares the contents of two individual files, rather than providing a complete recursive folder comparison by itself. For example, fc /b file1.bin file2.bin performs a byte-by-byte comparison of two files. The paths must point to the files you want to compare.

File Explorer can help with basic inspection, such as sorting a folder by name, size, or date modified, but it does not provide a full two-folder content-diff view. File size and modified date are clues, not proof: different files can share a size, and timestamps may change during copying or be preserved even when you need a content check.

Common problems and safe handling

  • Different root paths: Compare paths relative to each folder, as in the PowerShell example. Comparing complete paths would make every entry appear different.
  • Case or naming differences: Check how your chosen tool treats capitalization and names. On Windows, case behavior can depend on the directory and configuration, so do not assume every tool treats differently capitalized names identically.
  • Access denied or missing files: Confirm both paths are correct and that your account can read the folders. Avoid running a shell with elevated privileges unless necessary.
  • Changing files: If a program is editing files during comparison, results can be inconsistent. Close the program or compare a stable copy.
  • Unexpected copy or deletion: A comparison should not require changing either folder. Keep backups and do not approve synchronization or deletion until you have reviewed the direction and selected files.

For important data, compare a copy first and keep the original folders untouched until you have verified the results. A “same names” result does not establish that files are intact; use content comparison or hashes when integrity matters.

Frequently Asked Questions

Can Windows compare two folders without installing software?
Yes. PowerShell can compare file lists recursively, and Get-FileHash can compare file contents. These tools take more setup than a visual folder-diff application but are built into Windows.

How do I find files that are in one folder but not the other?
Compare the folders’ relative file paths, including subfolders if needed. In the PowerShell example, paths marked <= are only in the first folder, and paths marked => are only in the second.

Does comparing file names prove two files are identical?
No. Two files can have the same name but different contents. Compare their bytes, use matching SHA-256 hashes, or use a tool’s content-comparison mode.

Can I compare folders recursively?
Yes. PowerShell’s Get-ChildItem -Recurse includes files in subfolders. In a visual comparison tool, enable recursive or include-subfolders comparison.

What is the difference between a hash and a diff?
A hash gives a compact value for a file’s contents and helps determine whether files differ. A diff, typically for text, shows the actual lines or sections that changed.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.