通过命令行进行文件夹比较

发布于 2024-08-11 07:11:50 字数 201 浏览 2 评论 0原文

我想比较Windows(Vista,XP)上的两个文件夹,其中有大量大文件,我需要比较。如果我使用Beyond Compare或者类似的工具来比较文件夹,如果我手动进行的话会花费很多时间。我需要将该文件夹比较添加到批处理文件中。

那么在 Windows(XP、Vista)上,是否有任何命令(内置)或任何第三方工具/实用程序(商业或免费软件)可以使用命令行比较两个文件夹。

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

长安忆 2024-08-18 07:11:50
>diff -r Folder_A Folder_B

您可以在 GnuWin32 找到为 Windows 编译的 GNU diffutils。

>diff -r Folder_A Folder_B

You may find GNU diffutils compiled for windows at GnuWin32.

哽咽笑 2024-08-18 07:11:50

您可以使用内置命令COMP。这在一定程度上取决于您实际想要比较的内容。

比较两个文件的内容或
文件集。

COMP [数据1] [数据2] [/D] [/A] [/L]
[/N=数字] [/C]

data1 指定位置并
要比较的第一个文件的名称。

data2 指定位置和
要比较的第二个文件的名称。

/D 显示差异
十进制格式。

/A 显示
ASCII 字符的差异。

/L
显示差异的行号。

/N=number 仅比较第一个
每个指定的行数
文件。

/C 忽略大小写
比较文件时的 ASCII 字母。

要比较文件集,请在 data1 和 data2 参数中使用通配符。

使用类似 COMP c:\folder1 c:\folder2 的语法将 folder1 中的所有文件与 folder2 的内容进行比较。如果需要递归到子目录,则需要使用带有 FOR 循环以及 PUSHDPOPD 命令的批处理脚本。

如果您需要帮助,请发表评论。

There is the built in command COMP that you could use. It depends a little bit on what you actually want to compare.

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.

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.

Just leave a comment, if you need help with that.

原野 2024-08-18 07:11:50

我使用 Cygwin 版本的 Unix 命令行工具:

diff -r dir1 dir2

我还使用过 MinGW 过去。两者都有一些问题,但“足够接近”。对于视觉差异,我非常喜欢 WinMerge

I use Cygwin's versions of the Unix command line tools:

diff -r dir1 dir2

I've also used MinGW in the past. Both have a few gotchas, but are "close enough." For visual diffs, I like WinMerge pretty well.

一身骄傲 2024-08-18 07:11:50
forfiles /P %folder1Path% /S /C "cmd /c comp /a @path %folder2Path%\@file"

可以,但在第一次比较后我无法删除提示问题。

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.

残月升风 2024-08-18 07:11:50

根据 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

它在子目录中查找,不要问任何问题......

Basing on answer of Martin Tournoij I'v written next (and it working well):

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...

披肩女神 2024-08-18 07:11:50

我的两个目录具有相同的结构,只是对文件进行了一些版本更改。此外,我的目录只是 python 文件的文件夹。所以我逃脱了...

$ cat dir1/*.py > file1.txt 
$ cat dir2/*.py > file2.txt
$ diff file1 file2

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...

$ cat dir1/*.py > file1.txt 
$ cat dir2/*.py > file2.txt
$ diff file1 file2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文