set drv=c d e f g h i
for %%a in (%drv%) do find "12345" %%a:\123.txt>nul
if not errorlevel 1 goto find_y
goto find_not
:find_y
echo find str
goto end
:find_not
echo find not str
:end
这时问题就出来了不管字符串存在是否都没任何显示直接推出DOS如果把if语句改成if not errorlevel 3的话就都会显示找到文件。大家不妨试试究竟问题是出在哪个地方是不是find就不支持
多个分区文件找字符串只能对单个分区文件找字符串呢?作者: Climbing 时间: 2005-2-17 00:00 问题的关键出在For循环上,for循环的特点决定了只是将最后一次检查的结果传给后面的if命令,所以你的批处理相当于只是检查了i:\123.txt中是否有指定的字符串。解决办法是:将for循环中后面的do命令换成另一个批处理,假设叫chk.bat,调用格式为for ... do call chk.bat %%a
@echo off
find "12345" %1 > nul
if not errorlevel 1 goto _gotit
goto _quit
:_gotit
set found=1
:_quit你的批处理相应改为:
set drv=c d e f g h i
set found=0
for %%a in (%drv%) do call chk.bat %%a
if %found%==1 goto find_y
goto find_not
:find_y
echo found str
goto end:find_not
echo not found str
:end
for %%I in (drv found) set %%I= 作者: chenhui530 时间: 2005-2-17 00:00 谢谢Climbing兄我已想出更简单的方法了代码如下:set drv=c d e f g h i
for %%a in (%drv%) do if exist %%a:\123.txt set a=%%a
find "12345" %a%:\123.txt>nul
if not errorlevel 1 goto find_y
goto find_not
:find_y
echo find str
goto end
:find_not
echo find not str