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-09 03:53
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Problem with Comparing Two Files View 3,283 Replies 52
Floor 16 Posted 2008-07-09 18:59 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
If the code on floor 10 is feasible, then the efficiency should be higher.
:

@echo off&setlocal enabledelayedexpansion
for /f "tokens=1* delims= " %%a in (1.txt) do set "%%b=%%a"
for /f "delims=" %%a in (2.txt) do (
for /f "delims=" %%b in ('crc32 "%%a"') do (
if defined %%b echo !%%b! %%a
))
pause
致精致简!
Floor 17 Posted 2008-07-09 21:27 ·  中国 江苏 苏州 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
The code above doesn't work, but I still sincerely thank everyone.

I want to start with something simple. I have a very small CRC32 program

Download it from my ftp://quya.2mydns.com/crc32.com

This program runs under code page 437 and doesn't support long file names or directories with spaces, but the following code can get the correct result.

for /f "delims==" %i in (2.txt) do (if /i %~xi==.cat (crc32 %~fsi>>crc.txt) else (expand %~fsi %temp%\oembios.cat&crc32 %temp%\oembios.cat>>crc.txt))


The content of file 2.txt is as follows:

G:\IBM\oembios.cat
G:\IBM\OEMBIOS.CA_
G:\WXPOEM\IBM\I386\OEMBIOS.CA_
G:\xpdos\I386\OEMBIOS.CA_
G:\xpdos\WXPOEM\ACER\OEMBIOS.CAT
G:\xpdos\WXPOEM\ASUS\OEMBIOS.CA_
G:\xpdos\WXPOEM\DELL\OEMBIOS.CAT
G:\xpdos\WXPOEM\HPQ\OEMBIOS.CAT
G:\xpdos\WXPOEM\IBM\OEMBIOS.CAT
G:\xpdos\WXPOEM\LENOVO\OEMBIOS.CAT
F:\e\Backup\Tools\OEM 5 files\Acer\OEMBIOS.CA_
F:\e\Backup\Tools\OEM 5 files\COMPAQ\OEMBIOS.CA_
F:\e\Backup\Tools\OEM 5 files\HEDY\OEMBIOS.CA_
F:\e\Backup\Tools\OEM 5 files\HP\OEMBIOS.CA_
F:\e\Backup\Tools\OEM 5 files\IBM\OEMBIOS.CA_
F:\e\Backup\Tools\OEM 5 files\Legend\OEMBIOS.CA_
F:\e\Backup\Tools\OEM 5 files\SAMSUNG\OEMBIOS.CA_
F:\e\Backup\Tools\OEM 5 files\Sony\OEMBIOS.CA_
F:\FTP\Up\2003ent\OEMBIOS.CA_
E:\OEM files\ACER\OEMBIOS.CAT
E:\OEM files\LEGEND\OEMBIOS.CA_


The running result is as follows:

G:\IBM\oembios.cat D7A77612
C:\WINXP\TEMP\oembios.cat D7A77612
C:\WINXP\TEMP\oembios.cat D7A77612
C:\WINXP\TEMP\oembios.cat 90BBDCA0
G:\xpdos\WXPOEM\ACER\OEMBIOS.CAT 717B6EF3
C:\WINXP\TEMP\oembios.cat B20C65BF
G:\xpdos\WXPOEM\DELL\OEMBIOS.CAT B6F0EEFD
G:\xpdos\WXPOEM\HPQ\OEMBIOS.CAT CD4E1902
G:\xpdos\WXPOEM\IBM\OEMBIOS.CAT D7A77612
G:\xpdos\WXPOEM\LENOVO\OEMBIOS.CAT 5237B729
C:\WINXP\TEMP\oembios.cat 700A8481
C:\WINXP\TEMP\oembios.cat 74572CCF
C:\WINXP\TEMP\oembios.cat 162C7931
C:\WINXP\TEMP\oembios.cat 74572CCF
C:\WINXP\TEMP\oembios.cat D7A77612
C:\WINXP\TEMP\oembios.cat 7B06BD13
C:\WINXP\TEMP\oembios.cat 904CF15A
C:\WINXP\TEMP\oembios.cat 74572CCF
C:\WINXP\TEMP\oembios.cat 57E3E3DC
E:\OEM files~1\ACER\OEMBIOS.CAT 717B6EF3
C:\WINXP\TEMP\oembios.cat 7B06BD13


First, solve the following problem: how to restore the temporary directory C:\WINXP\TEMP\ to the original directory.

Then take it step by step. Thank you everyone. The old-fashioned mind is a bit not working well now.

[ Last edited by quya on 2008-7-9 at 09:42 PM ]
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 18 Posted 2008-07-09 21:36 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
More and more don't know what you're going to do?
G:\IBM\oembios.cat D7A77612
C:\WINXP\TEMP\oembios.cat D7A77612
C:\WINXP\TEMP\oembios.cat D7A77612
C:\WINXP\TEMP\oembios.cat 90BBDCA0
G:\xpdos\WXPOEM\ACER\OEMBIOS.CAT 717B6EF3
C:\WINXP\TEMP\oembios.cat B20C65BF
G:\xpdos\WXPOEM\DELL\OEMBIOS.CAT B6F0EEFD
G:\xpdos\WXPOEM\HPQ\OEMBIOS.CAT CD4E1902
G:\xpdos\WXPOEM\IBM\OEMBIOS.CAT D7A77612
G:\xpdos\WXPOEM\LENOVO\OEMBIOS.CAT 5237B729
C:\WINXP\TEMP\oembios.cat 700A8481
C:\WINXP\TEMP\oembios.cat 74572CCF
C:\WINXP\TEMP\oembios.cat 162C7931
C:\WINXP\TEMP\oembios.cat 74572CCF
C:\WINXP\TEMP\oembios.cat D7A77612
Are these the contents of crc.txt?
If yes, does that mean the code on floor 7 doesn't work?
致精致简!
Floor 19 Posted 2008-07-09 21:47 ·  中国 江苏 苏州 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
越来越不知道你要干什么了?
G:\IBM\oembios.cat D7A77612
C:\WINXP\TEMP\oembios.cat D7A77612
C:\WINXP\TEMP\oembios.cat D7A77612
C:\WINXP\TEMP\oembios.cat 90BBDCA0
G:\xpdos\WXPOEM\ACE ...

I didn't test your code at the unit this afternoon, sorry. Just tried it just now, it's correct and very fast.

But can it solve the problem of restoring the original directory in the case of a compressed file? The problem I mentioned on floor 17.

Can you explain the meaning of the sentence "for /f "tokens=1* delims= " %%a in (1.txt) do set %%b=%%a"? %%b is the second token, which is "*" in "1*", how can it be assigned a value, I really don't understand.

Edit again, I kind of understand. In this way, many variables are generated. The variable name takes the second token, and the assigned value is the first one. I am worried that if my file is very long, will there be too many variable names and errors?

Because when I was a child, I knew that I should save variable names and release variables in time. The memory I had back then was extremely small, and I didn't dare to use too many variables.


[ Last edited by quya on 2008-7-9 at 10:02 PM ]
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 20 Posted 2008-07-09 21:52 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Don't understand
Is there a compressed file in 2.txt?
Can crc32.exe decompress it? And decompress it to the C:\WINXP\TEMP\ directory?
What was the original directory?
致精致简!
Floor 21 Posted 2008-07-09 22:01 ·  中国 江苏 苏州 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
Originally posted by 26933062 at 2008-7-9 09:52 PM:
Don't understand
Is there a compressed file in 2.txt?
Can crc32.exe decompress it? And decompress it to the C:\WINXP\TEMP\ directory?
What was the original directory?


Yes, the file with the extension .ca_ is a compressed file, which needs to be expanded and then verified. Please refer to the decompression code in my 17th floor, thank you.
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 22 Posted 2008-07-09 22:11 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Did Laotu test my code for version 14? I added judgments and extraction for RAR files in it. You just need to modify it yourself.

[ Last edited by zw19750516 on 2008-7-9 at 10:20 PM ]
批处理之家新域名:www.bathome.net
Floor 23 Posted 2008-07-09 22:20 ·  中国 江苏 苏州 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
Originally posted by zw19750516 at 2008-7-9 10:11 PM:
Did Lao Tu test my code for version 14? I added judgment and extraction for RAR files in it. You just need to change the suffix yourself.


Thank you for your code, but

1. The extraction is not WINRAR, of course I can change this.
2. The most critical thing is that you extracted it in the current directory, and the current directory may be read-only, so it must be extracted to a temporary directory.

Due to the problem of 2, how to get the original directory has become a problem.
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 24 Posted 2008-07-09 22:33 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Improve according to your code on floor 17, get the original directory and file name

As for the variable benefit you mentioned, I haven't encountered this problem yet.
I made a simple test, and no error phenomenon was found with 100,000 variable names. My physical memory is 128m
But if the content of your 1.txt is very long, if you use the previous code for+findstr, you will wait until your hair turns white...

@echo off
for /f "delims==" %%i in (2.txt) do (
if /i %%~xi==.cat (crc32 %%~fsi>>crc.txt) else (
expand %~fsi %temp%\oembios.cat
for /f "tokens=2" %%a in ('crc32 %temp%\oembios.cat') do echo %%i %%a>>crc.txt
))


[ Last edited by 26933062 on 2008-7-9 at 10:34 PM ]
致精致简!
Floor 25 Posted 2008-07-09 22:35 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Oh, so troublesome, now this can solve your problem, right?

@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in (2.txt) do (
if /i "%%~xi" equ ".cat" (
crc32 %%~fsi>>crc.txt
) else (
expand "%%i" %temp%\oembios.cat
for /f "tokens=2" %%a in ('crc32 %temp%\oembios.cat') do set str=%%a
echo %%i !str!>>crc.txt
del /q %temp%\oembios.cat
))
for /f "tokens=1,2" %%a in (1.txt) do (
for /f "delims=" %%i in ('findstr "%%b" crc.txt') do echo %%a %%i
)
pause>nul


[ Last edited by zw19750516 on 2008-7-9 at 11:25 PM ]
批处理之家新域名:www.bathome.net
Floor 26 Posted 2008-07-09 22:59 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
I'm sorry, the 24th floor mentioned 100,000 variable names, but it wasn't fully tested. The actual test showed 40,000.
致精致简!
Floor 27 Posted 2008-07-09 23:06 ·  中国 江苏 苏州 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
The code on floors 24 and 25 has a missing % in %~fsi, but it's easy to fix.

The running result on floor 25 is not too ideal:

G:\IBM\oembios.cat D7A77612
G:\IBM\OEMBIOS.CA_ D7A77612
G:\WXPOEM\IBM\I386\OEMBIOS.CA_ D7A77612
G:\xpdos\I386\OEMBIOS.CA_ 90BBDCA0
G:\xpdos\WXPOEM\ACER\OEMBIOS.CAT 717B6EF3
G:\xpdos\WXPOEM\ASUS\OEMBIOS.CA_ B20C65BF
G:\xpdos\WXPOEM\DELL\OEMBIOS.CAT B6F0EEFD
G:\xpdos\WXPOEM\HPQ\OEMBIOS.CAT CD4E1902
G:\xpdos\WXPOEM\IBM\OEMBIOS.CAT D7A77612
G:\xpdos\WXPOEM\LENOVO\OEMBIOS.CAT 5237B729
F:\e\Backup\Tools\OEM 5 files\Acer\OEMBIOS.CA_ ??
F:\e\Backup\Tools\OEM 5 files\COMPAQ\OEMBIOS.CA_ ??
F:\e\Backup\Tools\OEM 5 files\HEDY\OEMBIOS.CA_ ??
F:\e\Backup\Tools\OEM 5 files\HP\OEMBIOS.CA_ ??
F:\e\Backup\Tools\OEM 5 files\IBM\OEMBIOS.CA_ ??
F:\e\Backup\Tools\OEM 5 files\Legend\OEMBIOS.CA_ ??
F:\e\Backup\Tools\OEM 5 files\SAMSUNG\OEMBIOS.CA_ ??
F:\e\Backup\Tools\OEM 5 files\Sony\OEMBIOS.CA_ ??
F:\FTP\Up\2003ent\OEMBIOS.CA_ 57E3E3DC
E:\OEM ??
E:\OEM files\LEGEND\OEMBIOS.CA_ ??


The running result on floor 24 is nearly perfect:

G:\IBM\oembios.cat D7A77612
G:\IBM\OEMBIOS.CA_ D7A77612
G:\WXPOEM\IBM\I386\OEMBIOS.CA_ D7A77612
G:\xpdos\I386\OEMBIOS.CA_ 90BBDCA0
G:\xpdos\WXPOEM\ACER\OEMBIOS.CAT 717B6EF3
G:\xpdos\WXPOEM\ASUS\OEMBIOS.CA_ B20C65BF
G:\xpdos\WXPOEM\DELL\OEMBIOS.CAT B6F0EEFD
G:\xpdos\WXPOEM\HPQ\OEMBIOS.CAT CD4E1902
G:\xpdos\WXPOEM\IBM\OEMBIOS.CAT D7A77612
G:\xpdos\WXPOEM\LENOVO\OEMBIOS.CAT 5237B729
F:\e\Backup\Tools\OEM 5 files\Acer\OEMBIOS.CA_ B20C65BF
F:\e\Backup\Tools\OEM 5 files\COMPAQ\OEMBIOS.CA_ B20C65BF
F:\e\Backup\Tools\OEM 5 files\HEDY\OEMBIOS.CA_ B20C65BF
F:\e\Backup\Tools\OEM 5 files\HP\OEMBIOS.CA_ B20C65BF
F:\e\Backup\Tools\OEM 5 files\IBM\OEMBIOS.CA_ B20C65BF
F:\e\Backup\Tools\OEM 5 files\Legend\OEMBIOS.CA_ B20C65BF
F:\e\Backup\Tools\OEM 5 files\SAMSUNG\OEMBIOS.CA_ B20C65BF
F:\e\Backup\Tools\OEM 5 files\Sony\OEMBIOS.CA_ B20C65BF
F:\FTP\Up\2003ent\OEMBIOS.CA_ 57E3E3DC
E:\OEM ??
E:\OEM files\LEGEND\OEMBIOS.CA_ 57E3E3DC


But I can't figure out why the second-to-last result is like this!

I carefully checked the code, and there are no errors.

Testing with the following statement is also okay, really frustrating!

for /f "delims=" %i in (2.txt) do echo %~fsi


Everyone has worked hard!!! Thanks a million!!

[ Last edited by quya on 2008-7-9 at 11:08 PM ]
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 28 Posted 2008-07-09 23:09 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
If you don't generate the temporary crc.txt:

@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in (2.txt) do (
if /i "%%~xa" equ ".cat" (
for /f "tokens=2" %%d in ('crc32 %%~fsa') do set str=%%d
) else (
expand "%%a" %temp%\oembios.cat
for /f "tokens=2" %%d in ('crc32 %%temp%\oembios.cat') do set str=%%d
)
for /f "tokens=1,2" %%b in (1.txt) do echo !str!|findstr "%%c">nul&&echo %%b %%a !str!
del /q /f %temp%\oembios.cat
)
pause>nul


[ Last edited by zw19750516 on 2008-7-9 at 11:31 PM ]
批处理之家新域名:www.bathome.net
Floor 29 Posted 2008-07-09 23:16 ·  中国 江苏 苏州 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
After carefully checking, there is still an issue.

F:\e\Backup\Tools\OEM 5文件\Acer\OEMBIOS.CA_ B20C65BF
F:\e\Backup\Tools\OEM 5文件\COMPAQ\OEMBIOS.CA_ B20C65BF
F:\e\Backup\Tools\OEM 5文件\HEDY\OEMBIOS.CA_ B20C65BF
F:\e\Backup\Tools\OEM 5文件\HP\OEMBIOS.CA_ B20C65BF
F:\e\Backup\Tools\OEM 5文件\IBM\OEMBIOS.CA_ B20C65BF
F:\e\Backup\Tools\OEM 5文件\Legend\OEMBIOS.CA_ B20C65BF
F:\e\Backup\Tools\OEM 5文件\SAMSUNG\OEMBIOS.CA_ B20C65BF
F:\e\Backup\Tools\OEM 5文件\Sony\OEMBIOS.CA_ B20C65BF


Here, all are the same.
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 30 Posted 2008-07-09 23:16 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Originally posted by quya at 2008-7-9 23:06:
There is a missing % in the code %~fsi on floors 24 and 25, but it's easy to fix.

The running result on floor 25 is not too ideal:



The running result on floor 24 is close to perfect:



But I can't figure out why the second-to-last result is like this?!!
...

Is the 1.txt redundant?
批处理之家新域名:www.bathome.net
Forum Jump: