且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用批处理命令比较文件夹和子文件夹文件

更新时间:2023-09-25 23:16:22

我根本不会使用批处理文件来完成此任务. BeyondCompare 正是在这里做到这一点,而且看起来还不错.

I would not use a batch file at all to accomplish this task. BeyondCompare is here to do exactly that, and does it seemingly well.

另一方面,您现在真的想通过批处理文件来执行此操作,建议您安装一个名为

Now on the other hand you really wanna do it via batch file, I'd suggest you install a tool called diff tools, and you'll be able to do something like:

diff.exe <file1> <file2> <htmlfile>

在命令行上.

希望有帮助

更新 作为您的评论的后续,我写了这篇,对我来说似乎也很有效,并且不使用任何外部工具.这是一个简单的示例,但是您可以使其变得更好.

UPDATE As a follow up to your comment, I write this, which also seems to work for me, and doesn't use any external tool. This is a simple example, but you can make it better.

如果存在compare.log del compare.log 如果存在missing.log del missing.log

if exist compare.log del compare.log if exist missing.log del missing.log

for /f "delims=" %%a in ('dir/b/a-d c:\test\1') do (
    if exist "C:\test\2\%%a" (
        fc "c:\test\%%a" "C:\test1\%%a" >> compare.log
    ) else (
        echo %%a is missing >> missing.log
    )
)

暂停