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-06-20 04:43
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » The FOR command under the blank directory is confused View 1,593 Replies 9
Original Poster Posted 2006-07-13 19:26 ·  中国 河南 郑州 电信
中级用户
Credits 207
Posts 41
Joined 2004-10-24 00:00
21-year member
UID 32885
Gender Male
Status Offline
Suppose

C:\Program Files\Internet Explorer\
exists 1.txt 2.txt
Execute
cd \
c:
dir /s /b 1.txt >ml.txt
dir /s /b 2.txt >>ml.txt
for /f %%i in (ml.txt) do @echo %%i | del %%i

The final result is not successful
Under the command line, use
for /f %i in (c:\ml.txt) do @echo %i
It shows: C:\Program
It doesn't show the entire path. I don't understand. For Program Files, it only shows the part before the space, not the entire path. So it's impossible to delete the file. How to avoid this space?
Tried these two
for /f %i in (c:\ml.txt) do @echo " %i"
for /f %i in (c:\ml.txt) do @echo %~fi


None of them work
:( I don't understand.

[ Last edited by willsort on 2006-7-23 at 13:14 ]
Floor 2 Posted 2006-07-14 09:36 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
Hehe, do you know WHY? That's because your for command is missing a DELIMS= parameter. for /f " delims=" %i in (c:\ml.txt) do @echo %i Try it again, haha...........
Floor 3 Posted 2006-07-14 12:12 ·  中国 河南 郑州 电信
中级用户
Credits 207
Posts 41
Joined 2004-10-24 00:00
21-year member
UID 32885
Gender Male
Status Offline
thank bagpipe. It's okay. But still need to ask. Isn't delims the symbol to locate the delimiter? Is my previous failure because FOR itself defaults to the first column of each line in TOKEN? ^_^ It seems I still don't understand these parameters very well. "delims=" here, does it mean no delimitation, no delimiter? Need to study... Thanks a lot.

[ Last edited by flysp on 2006-7-14 at 12:26 ]
Floor 4 Posted 2006-07-14 13:10 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
Because the default for DELIMS is spaces and <TAB>, so when there are spaces in a line, it only takes the content before the first space, got it???
Floor 5 Posted 2006-07-14 23:57 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 160
Posts 75
Joined 2006-06-28 01:07
19-year member
UID 57661
Gender Male
Status Offline
"FOR itself defaults to the first column of each line in TOKEN"???

Sweat ah, I've been looking for the usage of for recently and actually didn't know there was such an important matter.
I can be considered to know how naive I am.

Unforgettable ah, the little one remembers:

For text lines with spaces, use delims=
Floor 6 Posted 2006-07-15 15:12 ·  中国 河南 郑州 电信
中级用户
Credits 207
Posts 41
Joined 2004-10-24 00:00
21-year member
UID 32885
Gender Male
Status Offline
Floor 7 Posted 2006-07-22 20:13 ·  中国 辽宁 大连 教育网
中级用户
★★
DOS之友
Credits 332
Posts 168
Joined 2005-10-06 00:00
20-year member
UID 43171
Gender Male
From 天涯
Status Offline
The command is worth us to have an in - depth understanding.
Floor 8 Posted 2006-10-02 19:20 ·  中国 湖北 武汉 电信
新手上路
Credits 4
Posts 2
Joined 2006-09-28 11:38
19-year member
UID 63933
Status Offline
Floor 9 Posted 2006-10-16 00:33 ·  中国 广东 东莞 电信
中级用户
★★
Credits 282
Posts 130
Joined 2006-09-20 22:25
19-year member
UID 63201
From 广东
Status Offline
Learning
~~~~好好学习
天天向上~~~~
Floor 10 Posted 2006-10-16 10:20 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
for /f " delims=" %i in (c:\ml.txt) do @echo %i

The default delimiter for for is space, and "delims=" cancels the default delimiter to extract the entire line content.

Using "tokens=*" can also achieve the same effect, which assigns all content after column zero to a variable %%?
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +1 2006-10-16 10:32
Forum Jump: