![]() |
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-24 00:01 |
47,812 topics / 349,917 posts / today 0 new / 48,274 members |
| DOS批处理 & 脚本技术(批处理室) » The FOR command under the blank directory is confused |
| Printable Version 1,733 / 9 |
| Floor1 flysp | Posted 2006-07-13 19:26 |
| 中级用户 Posts 41 Credits 207 | |
|
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 ] |
|
| Floor2 bagpipe | Posted 2006-07-14 09:36 |
| 银牌会员 Posts 425 Credits 1,144 From 北京 | |
|
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...........
|
|
| Floor3 flysp | Posted 2006-07-14 12:12 |
| 中级用户 Posts 41 Credits 207 | |
|
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 ] |
|
| Floor4 bagpipe | Posted 2006-07-14 13:10 |
| 银牌会员 Posts 425 Credits 1,144 From 北京 | |
|
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???
|
|
| Floor5 buddiyar | Posted 2006-07-14 23:57 |
| 初级用户 Posts 75 Credits 160 | |
|
"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= |
|
| Floor6 flysp | Posted 2006-07-15 15:12 |
| 中级用户 Posts 41 Credits 207 | |
| Floor7 IceCrack | Posted 2006-07-22 20:13 |
| 中级用户 Posts 168 Credits 332 From 天涯 | |
|
The command is worth us to have an in - depth understanding.
|
|
| Floor8 ke | Posted 2006-10-02 19:20 |
| 新手上路 Posts 2 Credits 4 | |
| Floor9 jieok3375 | Posted 2006-10-16 00:33 |
| 中级用户 Posts 130 Credits 282 From 广东 | |
|
Learning
|
|
| Floor10 pengfei | Posted 2006-10-16 10:20 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
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 %%? |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |