是否要在当前计算机的所有文件夹中搜索给定的 .exe 文件?下面的批处理文件使用了一个小技巧:它假定 .exe 文件位于 PATH 变量的文件夹之一中(通常会发生),因此搜索是立即的:
@echo off
for %%a in (filename.exe) do set filePath=%%~$PATH:a
if defined filePath echo %COMPUTERNAME% yes >> \\servername\location\test.txt
if NOT defined filePath echo %COMPUTERNAME% no >> \\servername\location\test.txt
编辑: 添加了整个磁盘的新版本
@echo off
set filePath=
for /R C:\ /D %%a in (*) do if exist "%%a\filename.exe" set filePath=%%a& goto continue
:continue
if defined filePath echo %COMPUTERNAME% yes >> \\servername\location\test.txt
if NOT defined filePath echo %COMPUTERNAME% no >> \\servername\location\test.txt