循环浏览文件夹树并在子文件夹中并行执行bat文件(访问子文件夹中的文件) [英] Loop through folder tree and execute bat file in subfolders in parallel(accessing the files in the subfolder)

查看:146
本文介绍了循环浏览文件夹树并在子文件夹中并行执行bat文件(访问子文件夹中的文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在父文件夹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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆