![]() |
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-08-09 04:56 |
47,811 topics / 349,895 posts / today 0 new / 48,253 members |
| DOS批处理 & 脚本技术(批处理室) » [Help] Problem with Comparing Two Files |
| Printable Version 3,286 / 52 |
| Floor1 quya | Posted 2008-07-09 11:28 |
| 高级用户 Posts 172 Credits 558 From 江苏 | |
|
Suppose I have the following 2 files
1.txt 2.txt Now I get a variable value, for example HEDY, which is the first value in the line in file 1.txt. I perform CRC32 checksum on the files in the paths in 2.txt (if it is a compressed file, first EXPAND), run CRC32.EXE, assume that the CRC output result is the 2nd token in the first line, then compare with the 2nd line value in file 1.txt, IF FIND, then assign the corresponding path to a variable. How to write code efficiently, concisely and understandably without using third-party programs? Thanks. To supplement, the CRC value check is only run once, but the result of the check may be called multiple times, so generating the following result file is more appropriate. [ Last edited by quya on 2008-7-9 at 12:01 PM ] |
|
| Floor2 huahua0919 | Posted 2008-07-09 12:40 |
| 银牌会员 Posts 780 Credits 1,608 | |
|
Is this something that checks if it's a virus copy after MD5 verification?
|
|
| Floor3 bat-zw | Posted 2008-07-09 13:19 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
Didn't use crc32, roughly wrote:
[ Last edited by zw19750516 on 2008-7-9 at 01:27 PM ] |
|
| Floor4 quya | Posted 2008-07-09 13:35 |
| 高级用户 Posts 172 Credits 558 From 江苏 | |
|
This problem I think is relatively complicated.
1. First, we need to extract the unzipped files to a temporary directory for verification. Because the original directory may be read-only, in this case, we need to save the original unzipped path value. 2. Just like I supplemented at the end of my first-floor post, I need to put the results into a file for multiple calls. As for the CRC running command format and the result, it's secondary. As long as we know it will definitely output a result. Just like in the 3rd floor, we just need to know that there is a CRC.TXT file, and there are various values in it. 3. The difficult part is to output the result after comparison, that is, to output the values of 1.txt, 2.txt, and crc.txt through a feature value again. |
|
| Floor5 26933062 | Posted 2008-07-09 13:41 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
It would be best to give some samples of the part of the crc.txt file...
|
|
| Floor6 quya | Posted 2008-07-09 13:53 |
| 高级用户 Posts 172 Credits 558 From 江苏 | |
Originally posted by 26933062 at 2008-7-9 01:41 PM: I can't remember the samples, but this is a common issue. To be universal, assume I first try to get the following a CRC file (actually this file may not be needed, as long as the final result, but let's take it step by step) CRC.TXT Finally, what I want to get is something like the following result Describing this problem in words is like this. My computer has a VOL version of XP installed, and now I want to change it to an OEM version. My motherboard has OEM characteristics, and I have a large number of OEMBIOS files available to replace the files needed by the system. In order to find the accurate OEMBIOS files, I put them in specific folders for the program to automatically find. Then I thought whether it could be more accurate. For example, if I put the wrong file in the folder, if I just put it randomly in a folder? Can I compile a batch file to quickly and accurately find it? The problem is like this. And I found that this problem can also be applied in other places, and there should be many similar application examples of finding. [ Last edited by quya on 2008-7-9 at 02:19 PM ] |
|
| Floor7 26933062 | Posted 2008-07-09 14:34 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
After talking a lot, I didn't understand your intention from floor 1 to floor 6.
I guess I wrote a code. Let's see if it's correct... Note: The situation where the file name and path in crc.txt contain spaces is not considered, and the situation where the first column of the content in 1.txt contains spaces is not considered. And under the premise that there are no duplicates in the??? part of crc.txt. : [ Last edited by 26933062 on 2008-7-9 at 02:42 PM ] |
|
| Floor8 quya | Posted 2008-07-09 15:24 |
| 高级用户 Posts 172 Credits 558 From 江苏 | |
|
If I run (for simplicity, temporarily not considering the issue of extracting OEMBIOS.CA_ to the temporary directory OEMBIOS.CAT first)
Get a crc.txt, this is also simulated, actually it may not be that simple, but I will handle it. First question: How can I combine 2.txt and CRC.txt into the following file temp.txt (if the second question can be directly solved, this file can be omitted) temp.txt (among the table, only 2 values are real, others are virtual by me) Path CRC value Second question How to get the following file according to temp.txt and 1.txt through a common CRC value Third question Do not simplify the steps, solve my actual problem. Actually, CRC is just a transition, I just find the directory of the specific file I need through the CRC value, and this specific file may be in a CAB compression on a read-only disk, I have to decompress it first and then detect. If the complicated steps I mentioned above are not needed, then it is the best. The final result I really need is similar to the following style: There are no restrictions on the following 2 values, there may be only one value, or no result if not found. [ Last edited by quya on 2008-7-9 at 04:10 PM ] |
|
| Floor9 26933062 | Posted 2008-07-09 16:16 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
The key point is that we don't know what the result of running crc32.exe is.
You first run the following code and post the result to see. : |
|
| Floor10 terse | Posted 2008-07-09 16:19 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
```
@echo off for /f "delims=" %%j in (2.txt) do ( for /f "delims=" %%j in ('crc32 "%%i"') do ( for /f "delims=" %%k in ('findstr /ic:"%%j" "1.txt"') do ( if not "%%k"=="" echo %%k %%i ) ) ) pause ``` |
|
| Floor11 quya | Posted 2008-07-09 16:45 |
| 高级用户 Posts 172 Credits 558 From 江苏 | |
|
To: Floor 9
I don't have CRC software right now. I won't know until晚上. You can assume the simplest one, which is CRC32.EXE Filename outputs the CRC value. Because no matter the actual CRC running result, I know how to handle it. This isn't the key. To: Floor 10 I'll verify your code after get off work. Three nested FORs make me dizzy. Maybe your code will run correctly when the OEMBIOS is fully decompressed, but considering the compressed OEMBIOS.CA_, the situation will be complicated. Can you generate the intermediate file first so that I can parse it to solve the actual problem? Thank you everyone. |
|
| Floor12 quya | Posted 2008-07-09 17:10 |
| 高级用户 Posts 172 Credits 558 From 江苏 | |
|
The idea on floor 10 is basically accurate. I modified the second FOR loop according to the meaning of floor 10 and verified it.
The running result is: (Can it be further improved and made more efficient? Thanks!) %i is not displayed correctly as the path! My main purpose is to obtain the path. HEDY 162C7931 %i As for the acquisition of the CRC.TXT file, my preliminary idea is the following code, which has not been run and verified, and may need to use delayed variables and so on. [ Last edited by quya on 2008-7-9 at 05:13 PM ] |
|
| Floor13 zh159 | Posted 2008-07-09 17:23 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
The 10th floor had a wrong character, so there was a little error when running on the 12th floor
@echo off |
|
| Floor14 bat-zw | Posted 2008-07-09 17:28 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
Assume your WinRAR storage path is c:\progra~1\winrar\,as follows:
[ Last edited by zw19750516 on 2008-7-9 at 06:04 PM ] |
|
| Floor15 quya | Posted 2008-07-09 17:31 |
| 高级用户 Posts 172 Credits 558 From 江苏 | |
Originally posted by zh159 at 2008-7-9 05:23 PM: No, the path name is completely useless. Even if J is changed to I, the result is wrong. Thank you to floor 10 and other friends who helped. Can you take another look? I really can't figure it out. |
|
| 1 2 3 4 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |