|  | 
| 原帖由 chiannet 于 2011-9-17 14:12 发表  for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do if exist %%a:\%myfile% set driver=%%a
 这句存在缺陷,假定存在c:\123.exe和d:\123.exe,当找到c:\123.exe时,未跳出for循环,将会set dri ...
 如果中途跳出FOR循环,DOS下由FOR定义的%%a变量会失效,不好办哦。
 
 如果C大只是想定位到第一个找到的文件(但需中途不跳出循环),结合strings可以办到。
 
 @echo off
 set srcfile=empty
 set myfile=123.exe
 set _goto=333
 
 del tmp*.txt >nul
 for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do if exist %%a:\%myfile% echo %%a:\%myfile% >>tmp1.txt
 strings fs1=filesize tmp1.txt
 if "%fs1%"=="0" goto next
 strings srcfile=read tmp1.txt,1
 goto %_goto%
 
 :next
 for %%b in (c d e f g h i j k l m n o p q r s t u v w x y z) do if exist %%b:\mydir\%myfile% echo %%b:\mydir\%myfile% >>tmp2.txt
 strings fs2=filesize tmp2.txt
 if "%fs2%"=="0" goto nofile
 strings srcfile=read tmp2.txt,1
 goto %_goto%
 
 :nofile
 cls
 echo.
 echo  "没找到"
 goto end
 
 :333
 cls
 echo.
 echo 找到了 %srcfile%~~~~
 
 :end
 pause
 | 
 |