批处理运行某个文件夹下的文件该如何写?

来源:百度知道 编辑:UC知道 时间:2024/05/19 01:42:19
查找某个文件夹A里面的ABC.EXE,然后运行它,该文件夹可能在c盘,也可能在d盘,或者e盘,不能直接用搜索ABC.EXE,然后再运行,因为有同名的文件,只能运行特定的A文件夹里的ABC.EXE。 批处理该怎么写?谢谢!

1、@for %%i 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 for /f "delims=" %%a in ('dir %%i:\abc.exe /a-d/b/s') do echo %%a | find /i "\A\abc.exe" && start "" "%%a"

2、@for %%i 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 for /f "delims=" %%a in ('dir %%i:\abc.exe /a-d/b/s^|find /i "\A\abc.exe"') do start "" "%%a"

搞定了。~~~

@echo off
set "file=ABC.EXE"
set "folder=A"
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:\nul (
for /f "delims=" %%b in ('dir /a:-d /b /s "%%a:\%file%" 2^>nul') do (
for %%c in ("%%~pb") do if /i "%%~nc"=="!folder!" start "" "%%b"
)
)

@echo off
set str=ABC.EXE
set "drv=c d e f g h