windows 通过命令行进行文件夹比较
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1732838/
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
Folder Comparisons Via Command Line
提问by goldenmean
I want to compare two folders on Windows (Vista, XP) which have a large number of huge files, which I need to compare. If I use Beyond Compare or such tool to compare the folders, it is taking a lot of time if I do it manually. I need to add that folder comparison to batch file.
我想比较 Windows(Vista、XP)上有大量大文件的两个文件夹,我需要比较它们。如果我使用 Beyond Compare 或类似工具来比较文件夹,如果我手动进行比较会花费很多时间。我需要将该文件夹比较添加到批处理文件中。
So on Windows (XP, Vista), is there any command (built-in) or any 3rd party tool/utility (commercial or freeware - either) to compare two folders using the command line.
因此,在 Windows(XP、Vista)上,是否有任何命令(内置)或任何 3rd 方工具/实用程序(商业或免费软件)来使用命令行比较两个文件夹。
采纳答案by Frank Bollack
There is the built in command COMP
that you could use. It depends a little bit on what you actually want to compare.
COMP
您可以使用内置命令。这在一定程度上取决于您实际想要比较的内容。
Compares the contents of two files or sets of files.
COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C]
data1 Specifies location and name(s) of first file(s) to compare.
data2 Specifies location and name(s) of second files to compare.
/D Displays differences in decimal format.
/A Displays differences in ASCII characters.
/L Displays line numbers for differences.
/N=number Compares only the first specified number of lines in each file.
/C Disregards case of ASCII letters when comparing files.
To compare sets of files, use wildcards in data1 and data2 parameters.
比较两个文件或文件集的内容。
COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C]
data1 指定要比较的第一个文件的位置和名称。
data2 指定要比较的第二个文件的位置和名称。
/D 以十进制格式显示差异。
/A 显示 ASCII 字符的差异。
/L 显示差异的行号。
/N=number 只比较每个文件中第一个指定的行数。
/C 比较文件时忽略 ASCII 字母的大小写。
要比较文件集,请在 data1 和 data2 参数中使用通配符。
Use a syntax like COMP c:\folder1 c:\folder2
to compare all files in folder1
with the content of folder2
. If you need to recurse into the subdirectories, you need to use a batch script using a FOR
loop and the PUSHD
and POPD
command.
使用类似的语法COMP c:\folder1 c:\folder2
将所有文件folder1
与folder2
. 如果您需要递归进入子目录,则需要使用使用FOR
循环和PUSHD
andPOPD
命令的批处理脚本。
Just leave a comment, if you need help with that.
如果您需要帮助,请发表评论。
回答by ephemient
回答by Michael Brewer-Davis
回答by Luis Andrés García
forfiles /P %folder1Path% /S /C "cmd /c comp /a @path %folder2Path%\@file"
Will work, but I can't remove the prompt question after the first comparison is made.
会起作用,但我无法在第一次比较后删除提示问题。
回答by Дмитрий Никитин
Basing on answer of Martin Tournoij I'v written next (and it working well):
根据我接下来写的 Martin Tournoij 的回答(并且运行良好):
del a.txt
forfiles /P %1 /M *.c* /S /C "cmd /c comp /a @path @file /M" >> a.txt
forfiles /P %1 /M *.h /S /C "cmd /c comp /a @path @file /M" >> a.txt
forfiles /P %1 /M *.s /S /C "cmd /c comp /a @path @file /M" >> a.txt
It looks in subdirectories and don't ask any quiestions...
它在子目录中查找并且不询问任何问题...
回答by Dylan
My two directories have the same structure, just a few version changes to the files. Furthermore, my directory was just a folder of python files. So i got away with...
我的两个目录具有相同的结构,只是对文件进行了一些版本更改。此外,我的目录只是一个包含 python 文件的文件夹。所以我逃脱了...
$ cat dir1/*.py > file1.txt
$ cat dir2/*.py > file2.txt
$ diff file1 file2