用于比较 2 个目录并获取不同文件名的批处理文件 [dos]

发布于 2024-10-04 12:45:41 字数 317 浏览 7 评论 0原文

我将有 2 个目录,文件夹 1 具有设置的文件列表,文件夹 2 具有相同的设置文件列表,但包含更多文件。我需要获取folder2的“其他文件”
是否存在像文件比较(fc)这样的目录来返回差异?

编辑我目前正在使用dir创建2个列表,然后进行文件比较。现在我只需要解析 fc 的输出以仅包含文件名。

fc /a "C:\whatever\text1.txt" "C:\whatever\text2.txt" >> "C:\whatever\differences.txt"

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?

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

fc /a "C:\whatever\text1.txt" "C:\whatever\text2.txt" >> "C:\whatever\differences.txt"

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

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

发布评论

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

评论(2

百善笑为先 2024-10-11 12:45:41

批处理文件

@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

使用

环境:

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>

运行:

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>

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>
滥情空心 2024-10-11 12:45:41

首先对两个文件夹执行dir /s。然后使用fc /a来比较结果。

对于比这更好的事情(取决于您的需求),您将需要一个专门的工具。例如,查看 WindiffWinMerge

First do a dir /s on both folders. Then use fc /a to compare the results.

For anything better than that (depending in your needs) you'll need a specialized tool. For instance have a look at Windiff or WinMerge.

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