批处理搜索程序并运行它

2024-12-03 18:45:59
推荐回答(2个)
回答1:

@echo off
title 快速文件搜索
:loop
set /p filename=请输入你要查找的文件名(必须输入扩展名,支持通配符,如"*.jpg"):
if not defined filename (cls & goto loop)
echo 正在搜索中,请耐心等待......
for %%i in (c d e f g h) do (
dir /s/b %%i:\%filename% && start "%%i:\%filename%" || start d:\123.exe
exit

回答2:

@echo off
set "str=程序名.exe"
set "drv=c d e f g h i j k l m n o p q r s t"
for %%a in (%drv%) do (
if exist %%a: (
for /f "delims=" %%b in ('dir /s/b/a-d "%%a:\%str%" 2^>nul') do (
if not "%%b"=="" (
start "" "%%b"
exit
)
)
)
)
start "" "d:\123.exe"