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 19:48
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Compare a text file with N text files. If the content is the same as a certain file, then operate View 3,680 Replies 28
Floor 16 Posted 2005-03-22 00:00 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 40
Joined 2005-03-17 00:00
21-year member
UID 37149
Gender Male
Status Offline
Compfile DOS works normally. Thanks a lot!
Could everyone please provide where to download Strings/Varset? I've been looking for a few days but can't download it.
Floor 17 Posted 2005-03-22 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 18 Posted 2005-03-22 00:00 ·  中国 北京 方正宽带
初级用户
Credits 141
Posts 11
Joined 2004-09-30 00:00
21-year member
UID 31972
Gender Male
Status Offline
The commonly used command-line tools I use are downloaded here: Climbing's commonly used DOS command-line tools compressed installation package (about 11M)
First, thank you to climbing, and then I ask: Be a good person to the end, may I ask if climbing can roughly write some comments out? Otherwise, how to use it?
Floor 19 Posted 2005-03-23 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
I can't meet such a requirement (this can almost be regarded as an unreasonable request). There are probably hundreds of programs in my installation package. I can't write instructions and comments for these programs one by one. Most of the programs you can get help by running with the /? parameter (or -h, --help). If you don't understand, don't use them. There are also many program instruction documents in the same - name txt file in their respective directories. Please figure it out upstairs. Others don't have the obligation to teach you what to do one - to - one. Many times, learning things depends on your own efforts.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 20 Posted 2005-03-23 00:00 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 40
Joined 2005-03-17 00:00
21-year member
UID 37149
Gender Male
Status Offline
I changed Chehui530's code a bit, and the function is basically realized, but I always feel it's not perfect.
If my those txt, bat file names are not numbers but random English letters, how should I write it then?
My content is as follows:
TEST.bat
------------------------
@echo off
:start
string a=add %b%,1
compfile d:\mods.log %a%.log /v /a /s
if errorlevel 128 goto bat
if errorlevel 64 goto reture
:reture
string b=add %b%,1
goto start
if %b%==101 goto end
:bat
call %a%.bat

:end
Floor 21 Posted 2005-03-23 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
If it's random numbers, it's difficult
http://www.msfans.net/bbs/
Floor 22 Posted 2005-03-24 00:00 ·  中国 山西 太原 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re chenhui530:  This is not an issue of random numbers, but an issue of file traversal. That is to say, the owner wants to implement comparison with log files of any names, which can be fully achieved with for. If the operation is relatively complex, you can Call its subroutine within for.  As for comparison, FC can be fully used. Use FIND to find whether the output of FC contains the string of file non - existence difference. Haven't you already used it like this?  So, this program can currently meet the owner's requirements without the assistance of third - party programs.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 23 Posted 2005-03-24 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
It seems that brother willsortwillsort can't complete it without using third-party tools! Maybe I'm limited in knowledge! Please brother willsortwillsort publish a perfect program for everyone to learn
http://www.msfans.net/bbs/
Floor 24 Posted 2005-03-24 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
willsort made a mistake this time. The fc in DOS 7.1 simply doesn't have such a function.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 25 Posted 2005-03-24 00:00 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re chenhui530:
A bit off. The key issue is obtaining the main filename of the file. This is difficult to do with for, so a file traversal loop is used instead.
Regarding file traversal, if you've carefully read my previous post about file traversal, you'll understand that this program is just a variation of those programs. They all utilize an algorithm for obtaining a string of words from a text file based on the address of lines, columns/words, that is, using debug to generate a command line prefix without carriage returns and then chaining it into the text for processing. Using this method, you can also obtain the file extension, full path, directory it's in, file size, date and time, file attributes, etc. Even the relative path that's hard to obtain under XP can be gotten, but the complexity and efficiency of the algorithm reduce its practicality. Thus, you can better understand my helplessness.
Re quan_zhou:
The program requires execution in the command line. Since your design requirements are not clear, command line parameters are used to determine the files to compare. For example:
cmprcall c:\x.txt d:\ log
This is comparing c:\x.txt with all .log files under d:\.
Some suggestions regarding your design intention: For target matching and execution, I suggest using a separate batch program instead of calling multiple batches based on matching. This can save hard disk space overhead and simplify the program to some extent. Of course, there are exceptions if you have special needs that must be implemented this way. Also, there are some issues with that test.bat, such as if %b%==101 goto end is never executed, and the variable %b% increments by 2 each time, etc.
Re climbing:
The FC in DOS/Win9x does not return errorlevel, but FIND does, so FIND can be used to identify the comparison result of FC. My early file traversal program used this, and Brother chenhui530 also used it in the program under NT environment, of course, that was unnecessary. I wonder if you have something else in mind?

:: CmprCall.bat - Compare one file with a group of files and execute the corresponding batch
:: Will Sort - 11:54 2005-3-24
:: The program has been slightly modified and can be used with other names
@echo off
if "%1"=="$" goto %2
if "%3"=="" goto end
set src=%1
:MakeList
dir %2.\*.%3 | find /i " %3 " >~visit.lst
:MakePreLine
echo %0 $ Compare > ~visit.pre
for %%c in (rcx 17 w q) do echo %%c>> ~visit.asd
debug ~visit.pre < ~visit.asd > nul
rem if == chcp 936 > nul
:LoopVisit
copy /a ~visit.pre+~visit.lst ~visit.bat > nul
call ~visit.bat
if not "%matched%"=="" goto Clear
find "%0 $ Compare " /v < ~visit.bat > ~visit.lst
goto LoopVisit
:Compare
if "%3"=="" set matched=!failed!
if "%3"=="" goto end
if not exist d:\%3.bat goto end
fc %src% d:\%3.%4 | find "FC: no differences encountered" >nul
if not errorlevel 1 call %3.bat
if not errorlevel 1 set matched=!success!
goto end
:Clear
del ~visit.*
set matched=
set src=
:End

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 26 Posted 2005-03-24 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
To willsort, I don't know how to use DEBUG and really don't understand your program! Brother willsort, can you explain it?
http://www.msfans.net/bbs/
Floor 27 Posted 2005-03-24 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Re willsort: Yes, I was wrong. I didn't notice that under DOS 7.1, fc will return the string "The files are identical (in English)" after comparing the same files. I thought there would be no return value. No wonder Willsort is a master! I'm really in awe!
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 28 Posted 2005-03-25 00:00 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re chenhui530: No time to write much today, first give you a link to an old post: Batch processing for three file traversals (actually five)
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 29 Posted 2005-03-25 00:00 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 40
Joined 2005-03-17 00:00
21-year member
UID 37149
Gender Male
Status Offline
Thank you very much for everyone's help!
I am currently digesting Brother WillSort's batch processing. There are too many places I don't understand. I'll first go to check the information because I'm too novice.
I'll ask everyone for help when I really can't digest it. Thank you all!
Forum Jump: