I have directory structure:
我有目录结构:
DIR
|-component_name
|-source
|-setup.exe
|-another_component_name
|-source
|-setup.exe
|-yet_another_component_name
|-source
|-setup.exe
and so on...
In every directory like "component_name" I have setup.exe
file which installs current component to the palette component in Delphi. I need to make DIR/setup.bat
file that would make by-turn start of setup.exe
in every component directory in DIR
.
在像“component_name”这样的每个目录中,我都有setup.exe文件,它将当前组件安装到Delphi中的调色板组件中。我需要制作DIR / setup.bat文件,该文件将在DIR中的每个组件目录中依次启动setup.exe。
Thank you in advance.
先感谢您。
4 个解决方案
#1
I'm guessing that when you say "by-turn" you mean "one after the other" (i.e., execute the first setup.exe, let it complete, execute the second setup.exe, let it complete, etc).
我猜测当你说“by-turn”你的意思是“一个接一个”(即执行第一个setup.exe,让它完成,执行第二个setup.exe,让它完成,等等)。
If setup.exe is console-based, then you can just call your .EXEs directly. Each setup.exe will attach to the .BAT file's console window, thus blocking its execution until setup.exe completes. Similar to the for-loop example given by Bubbafat:
如果setup.exe是基于控制台的,那么您可以直接调用.EXE。每个setup.exe都将附加到.BAT文件的控制台窗口,从而阻止其执行,直到setup.exe完成。类似于Bubbafat给出的for循环示例:
for /f %%i in ('dir /b /s setup.exe') do %%i
However, if setup.exe is gui-based, then you'll have to use the CALL command. This will cause the .BAT file to wait for the called process to terminate before executing any more commands:
但是,如果setup.exe是基于gui的,那么您将必须使用CALL命令。这将导致.BAT文件在执行更多命令之前等待被调用进程终止:
for /f %%i in ('dir /b /s setup.exe') do call %%i
Now, if I misunderstood you and your EXEs are console-based and you want to execute them all at the same time without waiting for each to complete in turn, then you can use the START command. This will open a new console window for each EXE.
现在,如果我误解了您和您的EXE是基于控制台的并且您希望同时执行它们而不等待每个EXE依次完成,那么您可以使用START命令。这将为每个EXE打开一个新的控制台窗口。
for /f %%i in ('dir /b /s setup.exe') do start %%i
NB: Changed from "for /r" type loop to "for /f" since it will only return existing paths (unlike "for /r", which generates paths that may not exist).
注意:从“for / r”类型循环更改为“for / f”,因为它只返回现有路径(与“for / r”不同,后者生成可能不存在的路径)。
#2
example:
for /f %%i in ('dir /s /b setup.exe') do (
%%i
)
#3
I think you are asking "how do I run every setup.exe in my directory tree?".
我想你问的是“如何运行目录树中的每个setup.exe?”。
If the list is known ahead of time you can just create a batch file that runs the programs one after another. E.g.
如果提前知道列表,您可以创建一个接一个地运行程序的批处理文件。例如。
component_name\setup.exe
another_component_name\setup.exe
yet_another_component_name\setup.exe
But if the list is not static, and the order they run is not important, then you can use a for loop in a batch file like this:
但是如果列表不是静态的,并且它们运行的顺序并不重要,那么您可以在批处理文件中使用for循环,如下所示:
for /F %i in ('dir /B /S *.log') do %i
To preview what this would do add an "echo" before the last "%i" like:
要预览这会做什么,在最后一个“%i”之前添加一个“echo”,如:
for /F %i in ('dir /B /S *.log') do echo %i
If this is not what you meant please clarify what you are asking as it is not clear.
如果这不是您的意思,请澄清您的要求,因为它不清楚。
#4
Use this:
for /r %i in (setup.exe) do %i
(or, if you embed it into a .bat file, remember to double the % signs)
(或者,如果您将其嵌入到.bat文件中,请记住将%符号加倍)
#1
I'm guessing that when you say "by-turn" you mean "one after the other" (i.e., execute the first setup.exe, let it complete, execute the second setup.exe, let it complete, etc).
我猜测当你说“by-turn”你的意思是“一个接一个”(即执行第一个setup.exe,让它完成,执行第二个setup.exe,让它完成,等等)。
If setup.exe is console-based, then you can just call your .EXEs directly. Each setup.exe will attach to the .BAT file's console window, thus blocking its execution until setup.exe completes. Similar to the for-loop example given by Bubbafat:
如果setup.exe是基于控制台的,那么您可以直接调用.EXE。每个setup.exe都将附加到.BAT文件的控制台窗口,从而阻止其执行,直到setup.exe完成。类似于Bubbafat给出的for循环示例:
for /f %%i in ('dir /b /s setup.exe') do %%i
However, if setup.exe is gui-based, then you'll have to use the CALL command. This will cause the .BAT file to wait for the called process to terminate before executing any more commands:
但是,如果setup.exe是基于gui的,那么您将必须使用CALL命令。这将导致.BAT文件在执行更多命令之前等待被调用进程终止:
for /f %%i in ('dir /b /s setup.exe') do call %%i
Now, if I misunderstood you and your EXEs are console-based and you want to execute them all at the same time without waiting for each to complete in turn, then you can use the START command. This will open a new console window for each EXE.
现在,如果我误解了您和您的EXE是基于控制台的并且您希望同时执行它们而不等待每个EXE依次完成,那么您可以使用START命令。这将为每个EXE打开一个新的控制台窗口。
for /f %%i in ('dir /b /s setup.exe') do start %%i
NB: Changed from "for /r" type loop to "for /f" since it will only return existing paths (unlike "for /r", which generates paths that may not exist).
注意:从“for / r”类型循环更改为“for / f”,因为它只返回现有路径(与“for / r”不同,后者生成可能不存在的路径)。
#2
example:
for /f %%i in ('dir /s /b setup.exe') do (
%%i
)
#3
I think you are asking "how do I run every setup.exe in my directory tree?".
我想你问的是“如何运行目录树中的每个setup.exe?”。
If the list is known ahead of time you can just create a batch file that runs the programs one after another. E.g.
如果提前知道列表,您可以创建一个接一个地运行程序的批处理文件。例如。
component_name\setup.exe
another_component_name\setup.exe
yet_another_component_name\setup.exe
But if the list is not static, and the order they run is not important, then you can use a for loop in a batch file like this:
但是如果列表不是静态的,并且它们运行的顺序并不重要,那么您可以在批处理文件中使用for循环,如下所示:
for /F %i in ('dir /B /S *.log') do %i
To preview what this would do add an "echo" before the last "%i" like:
要预览这会做什么,在最后一个“%i”之前添加一个“echo”,如:
for /F %i in ('dir /B /S *.log') do echo %i
If this is not what you meant please clarify what you are asking as it is not clear.
如果这不是您的意思,请澄清您的要求,因为它不清楚。
#4
Use this:
for /r %i in (setup.exe) do %i
(or, if you embed it into a .bat file, remember to double the % signs)
(或者,如果您将其嵌入到.bat文件中,请记住将%符号加倍)