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-07-29 09:01
中国DOS联盟论坛 » 论坛回收站 » Problems with using for View 1,685 Replies 3
Original Poster Posted 2009-06-24 03:56 ·  中国 广东 深圳 电信
初级用户
Credits 33
Posts 30
Joined 2009-02-19 09:47
17-year member
UID 139249
Gender Male
Status Offline
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?
Floor 2 Posted 2009-06-24 04:08 ·  中国 福建 泉州 电信
银牌会员
★★★
Credits 1,276
Posts 469
Joined 2002-12-23 13:00
23-year member
UID 586
Gender Male
From 福建泉州
Status Offline
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
QQ:366840202
http://chenall.net
Floor 3 Posted 2009-06-24 04:12 ·  中国 广东 深圳 电信
初级用户
Credits 33
Posts 30
Joined 2009-02-19 09:47
17-year member
UID 139249
Gender Male
Status Offline
Thank you very much.  chenall
My purpose is to need the size of the hosts file.
Floor 4 Posted 2009-06-24 10:48 ·  中国 广东 揭阳 电信
初级用户
★★
Credits 131
Posts 72
Joined 2008-02-24 14:31
18-year member
UID 111317
Gender Male
Status Offline
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
Forum Jump: