You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows CMD中仅比较两个文件夹文件名:查询FC参数或替代命令

Comparing Filenames Between Two Folders in Windows

Great question! The fc command is built for comparing file contents, so it won’t focus solely on filenames by default. But don’t worry—there are a few straightforward ways to do exactly what you need using built-in Windows tools. Here are my go-to methods:

Method 1: Use dir + fc (Simple Text Comparison)

Since fc works well with text files, we can generate sorted lists of filenames for each folder and then compare those lists. Here’s how:

  1. Generate clean, sorted filename lists for both folders:
dir "C:\Your\Folder\Path\A" /b /on > FolderAFiles.txt
dir "C:\Your\Folder\Path\B" /b /on > FolderBFiles.txt
  • /b: Switches to "bare format" (only filenames, no extra metadata like size or date)
  • /on: Sorts the list alphabetically by filename, ensuring consistent order for accurate comparison
  1. Compare the two lists with fc:
fc FolderAFiles.txt FolderBFiles.txt

This will highlight any filenames that don’t match between the two folders.

  1. Clean up the temporary files when you’re done:
del FolderAFiles.txt FolderBFiles.txt

Method 2: Use robocopy (No Temporary Files Needed)

robocopy is usually used for file copying, but it’s also a powerful tool for comparing directory structures. You can use it to list filename differences directly without creating intermediate files:

robocopy "C:\Your\Folder\Path\A" "C:\Your\Folder\Path\B" /l /e /njh /njs /ndl /np /ns

Let’s break down the key parameters:

  • /l: "List only" mode—no actual copying happens
  • /e: Include subfolders (remove this if you don’t want to compare subdirectories)
  • /njh /njs: Hide job headers and summaries to keep output clean
  • /ndl: Don’t list directory names (focus only on filenames)
  • /np /ns: Hide progress and file size details

The output will show you filenames that exist in one folder but not the other. If you want to filter further:

  • Add /xl to see only files unique to Folder A (exclude files present in Folder B)
  • Add /xn to see only files unique to Folder B (exclude files present in Folder A)

Method 3: PowerShell (More Flexible & Readable Output)

If you’re comfortable with PowerShell, this method gives you a clear, structured view of differences:

# Get lists of filenames from both folders
$filesInA = Get-ChildItem -Path "C:\Your\Folder\Path\A" -Name
$filesInB = Get-ChildItem -Path "C:\Your\Folder\Path\B" -Name

# Compare the lists
Compare-Object -ReferenceObject $filesInA -DifferenceObject $filesInB

The output will clearly label which filenames are unique to each folder (indicated by <= for Folder A and => for Folder B).

Each method has its pros: dir+fc is great for quick text-based checks, robocopy is perfect for no-fuss directory comparisons, and PowerShell offers the most flexibility for scripting or detailed analysis.

内容的提问来源于stack exchange,提问作者G.C

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:54:09