.bat在子文件夹中运行所有.bat

时间:2014-01-04 17:04:05

标签: batch-file

我想创建一个批处理文件(run.bat)来执行名为execute的子目录中的所有文件。

我在这里看到了一些例子,但没有成功根据我的要求定制它们。

run.bat,其子文件夹可能位于任何位置。因此需要相对文件夹引用。

e.g。

  • c:\ somelocation \包含run.bat
  • c:\ somelocation \ execute \包含我要运行的所有其他批处理文件

能够以30秒的间隔启动它们也会很棒。

.bat编程对我来说是完全陌生的,所以任何帮助都将受到赞赏。

2 个答案:

答案 0 :(得分:1)

@echo off
pushd c:\somelocation\execute
for /f "delims=" %%x in ('dir /b /a-d *.bat') do start "" "%%x"&timeout /t 30 >nul
popd

应该完成工作。切换到该位置,执行每个.bat文件,在启动每个文件后等待30秒。


修改:是的,timeout不是choice。对于choice,它需要参数/t 30 /d y

答案 1 :(得分:0)

这会使用相对文件夹并添加延迟。

@echo off
for %%a in ("execute\*.bat") do (
   pushd "%%~dpa"
   call "%%~nxa"
   timeout /t 30 /nobreak >nul
   popd
)
pause