循环浏览文件夹树并在子文件夹中并行执行bat文件(访问子文件夹中的文件)

编程入门 行业动态 更新时间:2024-10-28 12:30:22
本文介绍了循环浏览文件夹树并在子文件夹中并行执行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文件(访问子文件夹中的文件)

本文发布于:2023-10-31 16:51:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546696.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   夹中   并在   文件夹   bat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!