Board logo

标题: if exist后面的文件名能否用通配符 [打印本页]

作者: joyoustar     时间: 2008-1-21 10:46    标题: if exist后面的文件名能否用通配符
比如:if exist abc*.txt command 我试过好像不行,请问能否使用通配符,或是用其它替代性方法呢?

作者: huahua0919     时间: 2008-1-21 12:16
要知道用if语句判断批量文件(通配符形式)意义不大,就象证明一个定理一样 要证明其正确性要判断很多种可能性,而判断其是否为假只要找出一个错例即可!
for /f %%i in ('dir/s/b abc*.txt') do if exist %%i command

作者: slore     时间: 2008-1-21 13:29
'dir/s/b abc*.txt' 列出的是存在的吧? 那个判断。。。。

作者: huahua0919     时间: 2008-1-21 13:45
Originally posted by slore at 2008-1-21 01:29 PM: 'dir/s/b abc*.txt' 列出的是存在的吧? 那个判断。。。。
不管存在还是不存在都一样,关键还在于command,用exit来让for只处理一次,效率也高!
for /f %%i in ('dir/s/b abc*.txt') do if exist %%i command 
[color=blue]exit[/color]
判断一次即可 [ Last edited by huahua0919 on 2008-1-21 at 01:57 PM ]

作者: fastslz     时间: 2008-1-21 14:03
for /f 不能少"delims="参数否则空格后面的字符被忽略 for /f "delims=" %%i in (....) do .....

作者: huahua0919     时间: 2008-1-21 14:06
恩,默认的是空格为分割符! 谢谢指点

作者: slore     时间: 2008-1-21 14:26
不太清楚你的意思…… 我的意思是: for /f ... in ('dir/s/b abc*.txt') do command 一定存在的,不用加if那句直接do啊

作者: joyoustar     时间: 2008-1-21 15:17
是不用加if,否则用不上FOR了,谢谢楼上所有的朋友。

作者: echo     时间: 2008-5-12 16:16
嗯,精辟…………