![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-23 14:10 |
47,812 topics / 349,917 posts / today 0 new / 48,273 members |
| DOS批处理 & 脚本技术(批处理室) » Compare a text file with N text files. If the content is the same as a certain file, then operate |
| Printable Version 4,260 / 28 |
| Floor1 quan_zhou | Posted 2005-03-17 00:00 |
| 初级用户 Posts 40 Credits 190 | |
|
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? |
|
| Floor2 chenhui530 | Posted 2005-03-18 00:00 |
| 高级用户 Posts 273 Credits 772 | |
|
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
|
|
| Floor3 quan_zhou | Posted 2005-03-18 00:00 |
| 初级用户 Posts 40 Credits 190 | |
|
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 |
|
| Floor4 chenhui530 | Posted 2005-03-19 00:00 |
| 高级用户 Posts 273 Credits 772 | |
|
I don't have the FC of 98. You upload one so that I can write a batch script for you
|
|
| Floor5 quan_zhou | Posted 2005-03-19 00:00 |
| 初级用户 Posts 40 Credits 190 | |
|
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". |
|
| Floor6 chenhui530 | Posted 2005-03-19 00:00 |
| 高级用户 Posts 273 Credits 772 | |
The following is the statement from quan_zhou on 2005-3-19 14:08:43: It should be like this if not errorlevel 1 echo find |
|
| Floor7 chenhui530 | Posted 2005-03-19 00:00 |
| 高级用户 Posts 273 Credits 772 | |
|
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.
|
|
| Floor8 quan_zhou | Posted 2005-03-19 00:00 |
| 初级用户 Posts 40 Credits 190 | |
|
Please help, chenhui530Open the attachment
|
|
| Floor9 chenhui530 | Posted 2005-03-20 00:00 |
| 高级用户 Posts 273 Credits 772 | |
|
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 |
|
| Floor10 小石头 | Posted 2005-03-20 00:00 |
| 初级用户 Posts 28 Credits 165 | |
|
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.
|
|
| Floor11 quan_zhou | Posted 2005-03-21 00:00 |
| 初级用户 Posts 40 Credits 190 | |
|
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? |
|
| Floor12 chenhui530 | Posted 2005-03-21 00:00 |
| 高级用户 Posts 273 Credits 772 | |
|
It seems that under DOS 7.1, FC has no return value
|
|
| Floor13 Climbing | Posted 2005-03-21 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
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.
|
|
| Floor14 quan_zhou | Posted 2005-03-21 00:00 |
| 初级用户 Posts 40 Credits 190 | |
|
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! |
|
| Floor15 Climbing | Posted 2005-03-21 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
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.
|
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |