China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-28 18:37
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Compare a text file with N text files. If the content is the same as a certain file, then operate View 3,675 Replies 28
Original Poster Posted 2005-03-17 00:00 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 40
Joined 2005-03-17 00:00
21-year member
UID 37149
Gender Male
Status Offline
Hello everyone! I would like to ask the predecessors. I want to compile a batch file under Dos to compare a text file with N text files. If it is the same as a certain file content, run a batch file with the same file name as the text file.
For example: if X.txt is the same as 1.txt content, then run 1.bat;
if X.txt is the same as 2.txt content, then run 2.bat.
May I ask how to compile this?
Floor 2 Posted 2005-03-18 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
The LZ you should list the TXT files corresponding to the batch processing to be executed! Otherwise, who knows how many there are! Which ones are they? So I wrote it comprehensively. Can it meet your requirements? The files to be compared, the files to be compared, and the BAT files all need to be placed in the same directory. for %%a in (*.txt) do for %%b in (*.txt) do fc %%a %%b | find "No differences were found" && %%~na.bat
http://www.msfans.net/bbs/
Floor 3 Posted 2005-03-18 00:00 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 40
Joined 2005-03-17 00:00
21-year member
UID 37149
Gender Male
Status Offline
I want to write a batch script. Under DOS 7.1, compare C:\X.txt with D:\1.txt to 99.txt. Among them, only one of 1.txt to 99.txt has the same content as X.txt.

TEST.bat, 1.txt to 99.txt, 1.bat to 99.bat are all in D:\
If the content of X.TXT is the same as that of 1.TXT, then run 1.BAT.
If the content of X.TXT is the same as that of 2.TXT, then run 2.BAT.
If the content of X.TXT is the same as that of 88.TXT, then run 88.BAT.
If the content of X.TXT is the same as that of 99.TXT, then run 99.BAT.
The content of the TEST.bat I wrote
FOR %%C IN (*.TXT|) DO FC %%C C:\X.TXT
----------------------------------------------------------------
TEST.bat has compared those files, but how can I run the corresponding BAT? Please give me some advice
Floor 4 Posted 2005-03-19 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
I don't have the FC of 98. You upload one so that I can write a batch script for you
http://www.msfans.net/bbs/
Floor 5 Posted 2005-03-19 00:00 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 40
Joined 2005-03-17 00:00
21-year member
UID 37149
Gender Male
Status Offline
I am using under DOS 7.1, and this upload is also.
I tried like this and it didn't work.
----------------test.bat-----------
fc c:\x.txt d:\1.txt
if errorlevel 1 goto 2
if errorlevel 0 call 1.bat
:2
fc c:\x.txt d:\2.txt
if errorlevel 1 goto 3
if errorlevel 0 call 2.bat
:3
--------------------------------------
But no matter whether the two files are the same or different, it returns "0".
Floor 6 Posted 2005-03-19 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
The following is the statement from quan_zhou on 2005-3-19 14:08:43:

I am using it under DOS 7.1, and this upload is also.
I tried like this and it didn't work
----------------test.bat-----------
fc c:\x.txt d:\1.txt
if errorlevel 1 goto 2
if errorlevel 0 call 1.bat
:2
fc c:\x.txt d:\2.txt
if errorlevel 1 goto 3
if errorlevel 0 call 2.bat
:3
--------------------------------------
But no matter whether the two files are the same or different, it returns "0".

It should be like this
if not errorlevel 1 echo find
http://www.msfans.net/bbs/
Floor 7 Posted 2005-03-19 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
Your such batch processing is unrealistic! To compare from 100 files, writing so many commands is not good. You pass me the FC of 98, and I'll write a batch processing which can be done with not much code.
http://www.msfans.net/bbs/
Floor 8 Posted 2005-03-19 00:00 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 40
Joined 2005-03-17 00:00
21-year member
UID 37149
Gender Male
Status Offline
Please help, chenhui530Open the attachment
Floor 9 Posted 2005-03-20 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
I tried FC.EXE under DOS 7.1 but there was no return value. Maybe there's a problem on my side. I'll provide the code for you to make a little change. Need a third - party tool STRINGS. If there's any problem, reflect it because I can't test! STRINGS.com can be downloaded from the software station: kaishi
strings a=add %b%,1
if not exist %a% fc x.txt %a%.txt>fc.txt
find "When the same FC code" fc.txt
if not errorlevel 1 %a%.bat
strings b=add %a%,1
if %b%==101 goto end
goto kaishi:end
http://www.msfans.net/bbs/
Floor 10 Posted 2005-03-20 00:00 ·  中国 河北 保定 联通
初级用户
Credits 165
Posts 28
Joined 2004-08-09 00:00
21-year member
UID 29892
Gender Male
Status Offline
The fc under DOS 7.1 cannot be used for file comparison in batch processing, so third - party tools must be introduced here. I found two on the Internet: filecomp and gscom. In addition, tools like md5sum or fsum can also be used to compare whether files are the same by calculating the md5 or crc32 values. Also, the for command under DOS 7.1 does not support the generation of digital variables in arithmetic sequences, so third - party programs like strings or varset above must be used to perform the operation of sequentially increasing numbers. Basically, the program above can be used by just changing the file comparison tool.
Floor 11 Posted 2005-03-21 00:00 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 40
Joined 2005-03-17 00:00
21-year member
UID 37149
Gender Male
Status Offline
Thanks for everyone's help!
I under DOS 7.1, no matter whether two files are the same or different, it returns 0.
Can we change the return value of FC.exe?
Floor 12 Posted 2005-03-21 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
It seems that under DOS 7.1, FC has no return value
http://www.msfans.net/bbs/
Floor 13 Posted 2005-03-21 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
The user above, "Little Stone" (which is my alternate account), has already explained that it's because fc under DOS 7.1 has no return value, so it can't be used to judge whether files are the same. Therefore, I provided two other file comparison tools for DOS, and both of these tools have return values. The download address for gscmp: http://www.programmersheaven.com/d/click.aspx?ID=F19947&URL=http%3A%2F%2Fwww.goldsealstudios.com%2Fcgi-bin%2Fdownload.pl%3fdl=gscmp.zip The download address for filecomp: http://www.programmersheaven.com/d/click.aspx?ID=F3062 In the environment of this thread, I recommend using gscmp because it's simple and easy to use, while filecomp has more functions but is more troublesome to use.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 14 Posted 2005-03-21 00:00 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 40
Joined 2005-03-17 00:00
21-year member
UID 37149
Gender Male
Status Offline
Thanks a lot for everyone's help!
I downloaded gscmp and it doesn't run normally in DOS 7.1, prompting that this program can't run in DOS mode.
It can run normally in XP's DOS.
Climbing, could you please trouble to give another one that can run in DOS 7.1 again, thanks!
Floor 15 Posted 2005-03-21 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Then use filecomp. I didn't test it under DOS 7.1. From the description, both programs are for the pure DOS environment, so I thought they could both be used in the DOS 7.1 environment. I think filecomp should be okay.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Forum Jump: