views:

840

answers:

4

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.

Thank you in advance.

A: 

I think you are asking "how do I run every setup.exe in my directory tree?".

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 /F %i in ('dir /B /S *.log') do %i

To preview what this would do add an "echo" before the last "%i" like:

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.

Bubbafat
> I think you are asking "how do I run every setup.exe in my >directory tree?".Exactly!What I needed was script:for /F %i in ('dir /B /S *.exe') do start %ipauseBut I also need to run Uninstall.bat from each directory (where setup.exe is located). How can I make it with this .bat script? I have read the [post]: http://stackoverflow.com/questions/649634/how-do-i-run-a-bat-file-in-the-background-from-another-bat-file but it is all the same - I can't understand.
phpcoder
+1  A: 

example:

for /f %%i in ('dir /s /b setup.exe') do (
%%i
)
Jeremy E
using this output error in console is "file not found"
phpcoder
Put %%i in quotes.
Joey
A: 

Use this:

for /r %i in (setup.exe) do %i

(or, if you embed it into a .bat file, remember to double the % signs)

lavinio
A: 

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).

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:

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:

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.

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).

totorocat
Thank you!!!for /r %%i in (setup.exe) do %%i Works fine!Yeah, setup.exe is console-based, but I also need to run Uninstall.bat from each directory "one after the other" (where setup.exe is located). How can I make it with, for example, uninst.bat script? I have read the stackoverflow.com/questions/649634/ but I can't understand how can I run the .bat from another bat in loop. Please, help.
phpcoder
Just replace "setup.exe" with "uninst.bat". For example: for /f %%i in ('dir /b /s uninst.bat') do %%i
totorocat
Excuse me, but I've forgotten to say that uninst.bat contains only this string: "setup.exe" /uninstall So I need to run the .bat from another .bat in loop and the last .bat makes execution .exe with key...
phpcoder