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-08-01 12:38
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Can batch processing achieve such a function??? View 1,847 Replies 8
Original Poster Posted 2005-01-27 00:00 ·  中国 湖北 武汉 电信
初级用户
Credits 134
Posts 7
Joined 2005-01-14 00:00
21-year member
UID 35328
Gender Male
Status Offline
Compare d:\123\1.txt and \\server\123\1.txt. If the contents are the same, run d:\123\1.exe; if different, run \\server\123\2.exe. If possible, please tell me how to implement it. Thanks
Floor 2 Posted 2005-01-28 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
@echo off
fc d:\123\1.txt \\server\123\1.txt > nul
if errorlevel 1 goto _runserver
if errorlevel 0 goto _runlocal
goto _quit
:_runserver
\\server\123\2.exe
goto _quit
:_runlocal
d:\123\1.exe
:_quitIn the above example, fc is used to compare files. Of course, you can use tools like CRC or md5sum to calculate the checksum values of two files to compare whether the files are the same. Also, remind you to write a good post title.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2005-01-29 00:00 ·  中国 广东 广州 白云区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
Brother Climbing: I found that under Win98, the return value of FC is 0 whether the two files are the same or not, which is a wrong judgment, isn't it?
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 4 Posted 2005-01-29 00:00 ·  中国 浙江 台州 椒江区 电信
中级用户
★★
Credits 447
Posts 126
Joined 2004-02-10 00:00
22-year member
UID 17150
Gender Male
Status Offline
The narrow sense of batch processing refers to a command sequence composed of DOS internal commands (such as copy, dir) and batch processing commands such as for, goto. The broad sense of batch processing refers to calling multiple external files according to certain requirements, and as long as the operations supported by external commands are concerned, batch processing can be realized. In the above example, it is completely possible to write a program by yourself, return different values according to whether two files are the same or not, and then use if errorlevel to handle it.
从来不用别人的东西,要用,也先改成自己的再说!
Floor 5 Posted 2005-01-29 00:00 ·  中国 广东 广州 白云区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
Haha, batch processing also has narrow and broad senses. I always thought there were only simple and complex ones. crshen: Do you mean to write a more perfect FC? I support you! Shake hands first...
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 6 Posted 2005-02-01 00:00 ·  中国 浙江 台州 电信
中级用户
★★
Credits 447
Posts 126
Joined 2004-02-10 00:00
22-year member
UID 17150
Gender Male
Status Offline
The following is a statement from JonePeng on 2005-1-29 22:46:53:
crshen: Do you mean to write a more complete FC?
I support you! Let's shake hands first...


I took some time today to write a small program specifically for comparing text files. The usage is:

fc.exe file1 file2 ; Compare file1 and file2 byte by byte

fc.exe file1 file2 /blank ; When comparing the two files, ignore all spaces, for example, "abcd " and "a bc d" are the same.

After comparison, return 1 indicating that the two files are the same, return 0 indicating differences, and return 2 indicating an error occurred during program operation.

There are test files inside. Open the attachment

从来不用别人的东西,要用,也先改成自己的再说!
Floor 7 Posted 2005-02-01 00:00 ·  中国 广东 广州 白云区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
Great! And it can compare files larger than 64K. I wonder which compiler was used?
P.S.: The last word in the returned message "Two files are NOT eaqule!" is incorrect; it should be "equal".
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 8 Posted 2005-02-01 00:00 ·  中国 浙江 台州 电信
中级用户
★★
Credits 447
Posts 126
Joined 2004-02-10 00:00
22-year member
UID 17150
Gender Male
Status Offline
Thanks JonePeng, the errors have been corrected and re-uploaded. I used Turbo C 2.0 for compilation. I feel that the binary comparison function is generally not used in batch processing, so I didn't add it to reduce the program size. I wonder if the expert has any other suggestions?
从来不用别人的东西,要用,也先改成自己的再说!
Floor 9 Posted 2005-02-01 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 crshen:
Just downloaded, not tested yet, let's give a few functional suggestions first, for reference only. Binary comparison is still widely applied in batch processing, such as comparing two disk image files, comparing the same pictures among multiple pictures. The following suggestions are for binary comparison.
1. Add comparison of multiple files, for example, compare all similar pictures among a large number of pictures;
2. Add file similarity index, for example, two files have an 80% similarity rate;
3. Add file update comparison, for example, which of the two WORD documents is more up-to-date;
4. Improve file comparison speed, select a non-byte-by-byte comparison algorithm, for example, generate MD5 respectively and then compare.
Wish you success!
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Forum Jump: