dos批处理中的神奇for命令....
从命令行
for /f "tokens=*" %f in ('dir .\foo* /ad/b') do rd "%f" /s/q
从批处理文件
for /f "tokens=*" %%f in ('dir .\foo* /ad/b') do rd "%%f" /s/q
/f 运行括号中 '' 中的命令,并对其进行标记。通过说 tokens=* 所有文件/目录名称进入一个变量 %f
这是一个例子
C:\temp>md foo3
C:\temp>md foo2
C:\temp>md foo1
C:\temp>dir
Volume in drive C is TEST
Volume Serial Number is F47F-AAE1
Directory of C:\temp
18/06/2012 09:42 p.m. <DIR> .
18/06/2012 09:42 p.m. <DIR> ..
18/06/2012 09:42 p.m. <DIR> foo1
18/06/2012 09:42 p.m. <DIR> foo2
18/06/2012 09:42 p.m. <DIR> foo3
0 File(s) 0 bytes
5 Dir(s) 131,009,933,312 bytes free
C:\temp>for /f "tokens=*" %f in ('dir .\foo* /ad/b') do rd "%f" /s/q
C:\temp>rd "foo1" /s/q
C:\temp>rd "foo2" /s/q
C:\temp>rd "foo3" /s/q
C:\temp>dir /ad
Volume in drive C is TEST
Volume Serial Number is F47F-AAE1
Directory of C:\temp
18/06/2012 09:42 p.m. <DIR> .
18/06/2012 09:42 p.m. <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 131,009,933,312 bytes free
C:\temp>