循环浏览文件夹树并在子文件夹中并行执行bat文件(访问子文件夹中的文件) [英] Loop through folder tree and execute bat file in subfolders in parallel(accessing the files in the subfolder)
问题描述
我正在尝试在父文件夹folder1
中有一个蝙蝠文件,这个名为run.bat
的蝙蝠文件将循环遍历所有子文件夹,并并行调用一个名为child.bat
的蝙蝠文件,这些child.bat
将必须访问同一文件夹中的另一个文件.
I am trying to have a bat file in folder1
which is the parent folder, and this bat file which named run.bat
will loop through all subfolders, and invoke a bat file named child.bat
in parallel, however, these child.bat
will have to access another files in the same folder.
例如:
Folder1 (have run.bat)
|
|_______Folder2
| |
| |_______aa.txt
| |
| |_______child.bat
|
|_______Folder3
|
|_______bb.txt
|
|_______child.bat
在Folder2
中的child.bat
,内容为:
type aa.txt
在Folder3
中的child.bat
,内容为:
type bb.txt
我知道关于如何循环子文件夹并在子文件夹中运行bat文件已经存在问题.但是我的问题是,bat文件必须访问位于同一子文件夹中的其他文件.如果不输入子文件夹(cd subfolder
),则child.bat
将不会成功执行.这是我尝试过的run.bat
的内容:
I know there are questions already there on how to loop though subfolders, and run bat file in subfolder. But my question is, the bat file have to access other files which located in the same child folder. and if we don't enter subfolder (cd subfolder
), the child.bat
will not successfully executed. Here is the content of run.bat
that I tried:
@echo off
for /d /r %%i in (*) do (
cd %%i
start "%%i\child.bat"
)
但是,失败了.
有什么想法吗?
推荐答案
根据您在评论中的额外信息,这应该对您有用.
Based upon your extra information in the comments, this should work for you.
@echo off
FOR /d /r %%i IN (*) DO (
if exist "%%i\child.bat" start "" /d "%%i" "%comspec%" /c "child.bat"
)
这篇关于循环浏览文件夹树并在子文件夹中并行执行bat文件(访问子文件夹中的文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!