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-08-14 02:02
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » [Help] Question for all the veterans! About the for command? View 639 Replies 6
Original Poster Posted 2003-07-21 00:00 ·  中国 广东 肇庆 电信
高级用户
★★
Credits 578
Posts 135
Joined 2003-07-10 00:00
23-year member
UID 6709
Gender Male
Status Offline
Why is it that when I run:
for /r c:\exe %a in (*.exe) do echo %~na

it always says:
Syntax error

??
Floor 2 Posted 2003-07-22 00:00 ·  中国 广东 广州 增城区 电信
元老会员
★★★
Credits 1,468
Posts 407
Joined 2002-10-21 00:00
23-year member
UID 34
Gender Male
From 广州
Status Offline
for is an important internal command in DOS. Its usage format is like this:
  FOR %C IN (item1......) DO command

  Here is an example:
If we want to view the contents of three text files A, B, and C, we would generally enter it like this:
C:\>TYPE A
A
C:\>TYPE B
B
C:\>TYPE C
C
Another method is:
C:\>for %c in (a,b,c) do echo %c
(The result is as follows)
C:\>echo a
a

C:\>echo b
b

C:\>echo c
c

If you want to display files of the .txt, .doc, and .WPS types in the current directory respectively, you can enter it like this:
for %i in (×.txt,*.doc,*.wps) do dir %i

In a batch file, the loop variable needs 2 percent signs (%%C), while if executed directly on the command line, only one % is needed.
欢迎大家观临我的个人主页:

http://dosdiy.bluepc.com.cn/
http://dosdiy.ys168.com/


EMAIL: lydong@china.com.cn lydong@yeah.net
----------------------------------------------
Floor 3 Posted 2003-07-22 00:00 ·  中国 广东 肇庆 电信
高级用户
★★
Credits 578
Posts 135
Joined 2003-07-10 00:00
23-year member
UID 6709
Gender Male
Status Offline
Thanks
Floor 4 Posted 2003-07-27 00:00 ·  中国 江苏 南京 电信
初级用户
Credits 178
Posts 16
Joined 2003-06-20 00:00
23-year member
UID 5609
Gender Male
Status Offline
Really learned something
Floor 5 Posted 2003-07-27 00:00 ·  中国 辽宁 沈阳 联通
初级用户
Credits 148
Posts 10
Joined 2003-07-16 00:00
23-year member
UID 7016
Gender Male
Status Offline
Sigh, do you have to learn programming before you can learn batch files?!
Floor 6 Posted 2003-07-27 00:00 ·  中国 广东 深圳 龙岗区 电信
中级用户
★★
Credits 356
Posts 54
Joined 2003-04-15 00:00
23-year member
UID 1552
Gender Male
Status Offline
Support, it would be even better if it were more detailed!
Floor 7 Posted 2004-08-03 00:00 ·  中国 上海 宝山区 电信
初级用户
★★
Credits 217
Posts 55
Joined 2004-08-02 00:00
22-year member
UID 29516
Gender Female
Status Offline
Right
Forum Jump: