![]() |
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-09-13 23:01 |
47,812 topics / 349,916 posts / today 0 new / 48,268 members |
| 论坛回收站 » Problems with using for |
| Printable Version 1,789 / 3 |
| Floor1 wwx0423 | Posted 2009-06-24 03:56 |
| 初级用户 Posts 30 Credits 33 | |
|
Is there any way to use the for instruction to analyze the byte part in 1.txt after I use dir c:\windows\system32\drivers\etc\hosts >>d:\1.txt.
Example: I first use dir c:\windows\system32\drivers\etc\hosts >>d:\1.txt to generate a 1.txt. The content of this text is as follows. ----------- The volume in drive C has no label. The serial number of the volume is 2C10-E32D Directory of c:\windows\system32\drivers\etc 2003-03-03 23:23 730 hosts 1 file 730 bytes 0 directories 2,955,378,688 available bytes --------------------- Now I need to use the for instruction to read the value 730 in 730 bytes and assign the value 730 to a variable. But I use for,/f,"skip=6 tokens=1,2,*",%%a in (d:\1.txt) do @each %%a>d:\2.txt There seems to be a problem. And there are 2 lines after 730 bytes, how to shield the following 2 lines.. I just want to get the value 730, and then compare whether it is equal to the value I want.. How to do it? |
|
| Floor2 chenall | Posted 2009-06-24 04:08 |
| 银牌会员 Posts 469 Credits 1,276 From 福建泉州 | |
|
Add a find command to locate the line at byte 730.
Also, if it's just the example above, there's really no need to be this complicated. You can directly use %~zi to get the file size. The example above directly displays the size (in bytes) of the hosts file for %i in (c:\windows\system32\drivers\etc\hosts) do echo %~zi The above command is executed directly in CMD. When placed in a batch script, you need to change it to %%i |
|
| Floor3 wwx0423 | Posted 2009-06-24 04:12 |
| 初级用户 Posts 30 Credits 33 | |
|
Thank you very much. chenall
My purpose is to need the size of the hosts file. |
|
| Floor4 lovelymorning | Posted 2009-06-24 10:48 |
| 初级用户 Posts 72 Credits 131 | |
|
Why use dir?
Directly use for %a in (c:\windows\system32\drivers\etc\hosts) do echo %~za Isn't it more convenient? It directly comes out, which is the size... PS: Note to replace with the content you need |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |