I have directory structure:
我有目录结构:
DIR
|-UNINSTALL.BAT
|-component_name
|-source
|-setup.exe
|-uninst.bat
|-another_component_name
|-source
|-setup.exe
|-uninst.bat
|-yet_another_component_name
|-source
|-setup.exe
|-uninst.bat
and so on...
等等...
In every directory like "component_name" I have setup.exe
file which installs current component to the palette component in Delphi. uninst.bat
contains only this string:
在像“component_name”这样的每个目录中,我都有setup.exe文件,它将当前组件安装到Delphi中的调色板组件中。 uninst.bat只包含此字符串:
"setup.exe" /uninstall
So I need to write UNINSTALL_ALL.bat
in DIR
that would run the uninst.bat in all component directories.
所以我需要在DIR中编写UNINSTALL_ALL.bat,它将在所有组件目录中运行uninst.bat。
Thank you in advance.
先感谢您。
5 个解决方案
#1
you could do it with this line:
你可以用这一行做到这一点:
for /f %%a in ('dir /b /s uninst.bat') do call %%a
note that the '%%' is necessary for batch files. if you are testing this on the command line, only use one '%'
请注意,批处理文件需要'%%'。如果您在命令行上测试它,只使用一个'%'
#2
That is kind of akward in a batch file. Though you could probably do it with the foreach
statement. I would suggest though that you have a look at Powershell which will definitely give you the power to do this simply and a whole lot more if you want it.
这在批处理文件中是一种尴尬。虽然你可以用foreach语句来做。我建议你看看Powershell,它肯定会让你有能力做到这一点,如果你想要的话还可以做更多。
#3
You want to use the "for" construct. Something like this:
您想使用“for”构造。像这样的东西:
for %%i in (component_name another_component_name yet_another_component_name) do %%i\uninst.bat
The double-escaping (%%) is necessary if you put the "for" loop in a batch file. If you are just typing it out in a command prompt, only use 1 %.
如果将“for”循环放在批处理文件中,则必须进行双重转义(%%)。如果您只是在命令提示符下键入它,则只使用1%。
Also, you may be able to use a wildcard to match against the directory names, if they follow some convention. Open up a command prompt and run "for /?" to see everything it can do...I believe there is a /d option to match against directories. That would look something like:
此外,如果符合某些约定,您可以使用通配符来匹配目录名称。打开命令提示符并运行“for /?”看到它可以做的一切...我相信有一个/ d选项来匹配目录。这看起来像是这样的:
for /D %%d in (component_*) do %%d\uninst.bat
(obviously, adjust the wildcard to match your component directories.)
(显然,调整通配符以匹配组件目录。)
#4
This should work:
这应该工作:
FOR /F %%a IN ('dir /b /s uninst.bat') DO START /B %%a
if you want them to wait each other, use this:
如果你想让他们互相等待,请使用:
FOR /F %%a IN ('dir /b /s uninst.bat') DO START /B /WAIT %%a
#5
The way you describe your problem, you have only one level of sub-directories and you always call the same batch, from the root. Therefore:
您描述问题的方式是,您只有一个级别的子目录,并且始终从根调用同一批次。因此:
Uninstall_all.cmd
@echo off
for /F "delims=" %%d in ('dir /b /ad') do cd "%%d"& start /b /w ..\uninstall.bat& cd ..
Should do the trick.
应该做的伎俩。
#1
you could do it with this line:
你可以用这一行做到这一点:
for /f %%a in ('dir /b /s uninst.bat') do call %%a
note that the '%%' is necessary for batch files. if you are testing this on the command line, only use one '%'
请注意,批处理文件需要'%%'。如果您在命令行上测试它,只使用一个'%'
#2
That is kind of akward in a batch file. Though you could probably do it with the foreach
statement. I would suggest though that you have a look at Powershell which will definitely give you the power to do this simply and a whole lot more if you want it.
这在批处理文件中是一种尴尬。虽然你可以用foreach语句来做。我建议你看看Powershell,它肯定会让你有能力做到这一点,如果你想要的话还可以做更多。
#3
You want to use the "for" construct. Something like this:
您想使用“for”构造。像这样的东西:
for %%i in (component_name another_component_name yet_another_component_name) do %%i\uninst.bat
The double-escaping (%%) is necessary if you put the "for" loop in a batch file. If you are just typing it out in a command prompt, only use 1 %.
如果将“for”循环放在批处理文件中,则必须进行双重转义(%%)。如果您只是在命令提示符下键入它,则只使用1%。
Also, you may be able to use a wildcard to match against the directory names, if they follow some convention. Open up a command prompt and run "for /?" to see everything it can do...I believe there is a /d option to match against directories. That would look something like:
此外,如果符合某些约定,您可以使用通配符来匹配目录名称。打开命令提示符并运行“for /?”看到它可以做的一切...我相信有一个/ d选项来匹配目录。这看起来像是这样的:
for /D %%d in (component_*) do %%d\uninst.bat
(obviously, adjust the wildcard to match your component directories.)
(显然,调整通配符以匹配组件目录。)
#4
This should work:
这应该工作:
FOR /F %%a IN ('dir /b /s uninst.bat') DO START /B %%a
if you want them to wait each other, use this:
如果你想让他们互相等待,请使用:
FOR /F %%a IN ('dir /b /s uninst.bat') DO START /B /WAIT %%a
#5
The way you describe your problem, you have only one level of sub-directories and you always call the same batch, from the root. Therefore:
您描述问题的方式是,您只有一个级别的子目录,并且始终从根调用同一批次。因此:
Uninstall_all.cmd
@echo off
for /F "delims=" %%d in ('dir /b /ad') do cd "%%d"& start /b /w ..\uninstall.bat& cd ..
Should do the trick.
应该做的伎俩。