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