比较两个文件夹并输出两个文件夹中丢失的文件

Not*_*PRO 8 command-line batch-file cmd.exe windows-10

我想比较两个文件夹,严格来说是文件名。(不是文件内容)。我在 Windows 10 上,想使用命令行工具。

这是可以解释问题的场景。

Folders
-------
source                  source2 
   - file_1                 - file_1
   - file_2                 - file_2
   - file_3                 - file_4
   - file_5                 - file_5
   - file_6                 - file_7


Output should be:
-----------------
Source  -> Missing files file_4  
Source2 -> Missing files file_3  
Run Code Online (Sandbox Code Playgroud)

我做了一些研究,有很多diff工具,但我对比较文件内容不感兴趣。我想要的只是比较两个文件夹并输出两个文件夹中缺少哪些文件(与另一个文件夹相比)。

我不喜欢使用 Powershell。

谢谢你。

use*_*274 10

robocopy (包含在最近的 Windows 版本中)可以一次性完成:

给定\source\\source2\带有一些常见文件和仅存在于任一文件夹中的文件,运行

robocopy source source2 /L /NJH /NJS /NP /NS
Run Code Online (Sandbox Code Playgroud)

产量

D:\Users\me\test\source\
         *EXTRA Datei                  only_in_source2.txt
           Neue Datei                  only_in_source.txt
Run Code Online (Sandbox Code Playgroud)

其中以 a 开头的行*仅表示source2(独立于操作系统语言)中的文件,而其他行仅表示source.

这些选项抑制了各种输出项,并/L注意仅列出差异而不是复制差异。