windows 批处理文件来比较 2 个目录并获取不同的文件名 [dos]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4248843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Batch file to compare 2 directories and get names of files that are different [dos]
提问by Nick Sinas
I will have 2 directories, folder1 with a set files list, and folder2 with the same set file list but with more files. I need to get folder2's "other files"
Does something exist like file compare (fc) for directories to return the differences?
我将有 2 个目录,folder1 带有一个集合文件列表,folder2 带有相同的集合文件列表但是有更多的文件。我需要获取folder2的“其他文件”
是否存在类似文件比较(fc)的目录以返回差异?
EDITI am currently creating 2 lists using dir
and then doing a file compare. Now I just need to parse the output of the fc
to only contain the file names.
编辑我目前正在创建 2 个列表dir
,然后进行文件比较。现在我只需要解析 的输出fc
以仅包含文件名。
fc /a "C:\whatever\text1.txt" "C:\whatever\text2.txt" >> "C:\whatever\differences.txt"
回答by frayser
Batchfile
批处理文件
@echo off
if "%2" == "" GOTO Usage
cd /D %1
if errorlevel 1 goto usage
for %%x in (*.*) do if NOT exist %2\%%x echo missing %2\%%x
cd /D %2
for %%x in (*.*) do if NOT exist %1\%%x echo missing %1\%%x
goto end
:usage
echo Usage %0 dir1 dir2
echo where dir1 and dir2 are full paths
:end
Usage
用法
Environment:
环境:
F:\so>dir /s dir1 dir2
Volume in drive F is WIN2K
Volume Serial Number is 921E-EC47
Directory of F:\so\dir1
2010-11-22 10:33 <DIR> .
2010-11-22 10:33 <DIR> ..
2010-11-22 10:33 13 a
2010-11-22 10:33 13 b
2010-11-22 10:33 13 c
3 File(s) 39 bytes
Directory of F:\so\dir2
2010-11-22 10:33 <DIR> .
2010-11-22 10:33 <DIR> ..
2010-11-22 10:33 13 a
2010-11-22 10:33 13 b
2010-11-22 10:33 13 c
2010-11-22 10:33 13 D
2010-11-22 10:33 13 E
5 File(s) 65 bytes
Total Files Listed:
5 File(s) 65 bytes
2 Dir(s) 219,848,704 bytes free
F:\so>
Running:
跑步:
F:\so\dir1>dirc f:\so\dir1 f:\so\dir2
F:\so\dir1>dirc f:\so\dir1 f:\so\dir2
missing f:\so\dir1\D
missing f:\so\dir1\E
F:\so\dir2>
回答by Michel de Ruiter
First do a dir /s
on both folders. Then use fc /a
to compare the results.
首先dir /s
在两个文件夹上做一个。然后fc /a
用来比较结果。
For anything better than that (depending in your needs) you'll need a specialized tool. For instance have a look at Windiff
or WinMerge
.
对于比这更好的任何东西(取决于您的需要),您将需要一个专门的工具。例如看看Windiff
或WinMerge
。