Volume in drive D is DATA
Volume Serial Number is C47C-9908
Directory of D:\tmp
09/26/2001 12:50 PM 18,426 alg0925.txt
12/02/2001 04:29 AM 795 bsample.txt
04/11/2002 04:18 AM 2,043 invitation.txt
4 File(s) 25,651 bytes
0 Dir(s) 4,060,700,672 bytes free
for 仍然可以解出其中的文件名并进行操作:
for /f "skip=5 tokens=5" %a in (todel.txt) do @if exist %a DEL %a
当然,上面这个命令是在进行删除,如果你只是想看看哪些文件将被操作,把DEL换成echo:
for /f "skip=5 tokens=5" %a in (todel.txt) do @if exist %a echo %a
FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]
或者,如果有 usebackq 选项:
FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]
Originally posted by liuyong at 2006-10-27 11:24 AM:
有点头大了!
作者: youlangyu 时间: 2008-9-19 11:03 for /r . %a in (*.txt) do @find "bluebear" %a
这个语句需要纠正一下:
for /r %a in (*.txt) do find "bluebear" %a
用搂主写的语句,没法执行,请核实。作者: zsr 时间: 2008-9-19 19:43 先收藏了,谢谢作者: hhzcl 时间: 2008-9-20 15:04 谢谢啦,收藏作者: aeihua 时间: 2008-9-28 15:34 对新手来说,确实看不太懂。作者: buddiyar 时间: 2008-9-29 10:15 for果然很强大,收藏慢慢研究作者: bailang3106 时间: 2008-9-29 11:12 FOR命令 太灵活了. 不太好掌握.. 用到是还成.作者: 55467015 时间: 2008-9-30 18:29
Quote:
Originally posted by youlangyu at 2008-9-19 11:03:
for /r . %a in (*.txt) do @find "bluebear" %a
这个语句需要纠正一下:
for /r %a in (*.txt) do find "bluebear" %a
用搂主写的语句,没法执行,请核实。
不用纠正,可以运行,在xp的cmd中可以正常运行.其中"@"可以不用 C:\22>for /r . %a in (*.txt) do @find "qwert" %a
---------- C:\22\1.TXT
qwert
---------- C:\22\2.TXT
sdfsdqwert
---------- C:\22\3.TXT
[ Last edited by 55467015 on 2008-9-30 at 18:32 ]作者: doszl 时间: 2008-10-5 13:00 收了慢慢学!作者: smallyangchao 时间: 2008-10-5 14:17 很好作者: inter7890 时间: 2008-10-5 15:31 收藏了 谢谢作者: killkk 时间: 2008-10-5 23:32 批处理中。。FOR命令真的是非常的强大。。呵呵~~自己刚刚茅塞顿开领悟了这个该死的tokens参数的命令..。。帖子讲得很详细。。。支持````作者: cysky 时间: 2008-10-7 13:17 看了楼主的帖子,觉得自己学习太浅了,以后要用心去学习了.作者: kimlx 时间: 2008-10-25 12:42 慢慢学作者: jchwylmh 时间: 2008-10-28 10:24 高手啊!我学习的榜样!作者: xie1986214 时间: 2008-10-29 13:42 for /f "tokens=5 skip=5" %1 in (1.txt) do @if exist %1 @echo %1
楼主 这句不行 请核实 我是在2003系统运行的 1.txt 是在同一目录下的
1.txt的内容
Volume in drive D is DATA
Volume Serial Number is C47C-9908
Directory of D:\tmp
09/26/2001 12:50 PM 18,426 alg0925.txt
12/02/2001 04:29 AM 795 bsample.txt
04/11/2002 04:18 AM 2,043 invitation.txt
4 File(s) 25,651 bytes
0 Dir(s) 4,060,700,672 bytes free作者: skypn520 时间: 2009-1-7 05:46 好详细的教程,上次看了一遍,忘记了.现在再来好好复习一遍,顺便留个足迹...作者: Areahe 时间: 2009-1-9 07:21 学习先咯。谢谢