Windows批处理循环扫描在1级子文件夹的文件 [英] windows batch to recursively scan files in 1 level subfolders
问题描述
我有很多项目(假设 D:\\项目\\
),每个都有它自己的目录。在某些目录(不是全部)有bat文件(声纳runner.bat
)。我想编写Windows批处理脚本sequentialy每个子文件夹运行此.bat文件:
I have many projects (let's say D:\Projects\
), each of which has it's own directory. In some of directories (not all) there is bat file (sonar-runner.bat
). I want to write windows batch script to run this .bat files sequentialy for each subfolders:
for /r %%i in (sonar-runner.bat) do (
@call "%%i"
pause
)
pause
不过使用这种方法我面临的问题在哪里目录内同一文件执行(例如 D:\\项目\\ MAIN \\内蒙古\\声纳runner.bat
) 。我不希望这种情况发生。我只是想看看通过项目文件夹文件(假设第1级的子文件夹)。有谁告诉我怎样才能做到这一点?
However using this approach I faced problem where the same files in inner directories are executed (for example D:\Projects\Main\Inner\sonar-runner.bat
). I don't want this to happen. I only want to look for file through projects folders (let's say subfolders of 1st level). Could anybody tell me how can I achieve that?
修改
我曾尝试另一种方法:
Edit I have tried another approach:
for /D %%i in (*) do (
for %%j in (%%i\sonar-runner.bat) do (
@call "%%j"
pause
)
)
pause
但我不肯定在这种情况下的表现。
But i'm not sure about performance in that case.
推荐答案
试试这个:
for /d /r "D:\Projects" %%i in (*) do (
pushd "%%~i"
echo(%%i|findstr /r "^.:\\[^\\]*\\[^\\]*$" >nul&&call sonar-runner.bat
popd
)
这篇关于Windows批处理循环扫描在1级子文件夹的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!