2009-05-06 59 views
1

考慮包含以下文件的目錄結構中的反覆調用Windows批處理文件:對其他批處理文件

\1.3\Baseline\GeneratedScripts\One\FullInstall.cmd 
\1.3\Baseline\GeneratedScripts\Two\FullInstall.cmd 
\1.3\Baseline\GeneratedScripts\Three\FullInstall.cmd 
\1.3\Patches\Patch1\GeneratedScripts\One\FullInstall.cmd 
\1.3\Patches\Patch1\GeneratedScripts\Two\FullInstall.cmd 
\1.3\Patches\Patch1\GeneratedScripts\Three\FullInstall.cmd 
\1.3\Patches\Patch2\GeneratedScripts\One\FullInstall.cmd 
\1.3\Patches\Patch2\GeneratedScripts\Two\FullInstall.cmd 
\1.3\Patches\Patch2\GeneratedScripts\Three\FullInstall.cmd 
\1.3\Patches\Patch3\GeneratedScripts\One\FullInstall.cmd 
\1.3\Patches\Patch3\GeneratedScripts\Two\FullInstall.cmd 
\1.3\Patches\Patch3\GeneratedScripts\Three\FullInstall.cmd 

我想建立一個Windows批處理文件InstallEnvironment.cmd其中:

  1. 取一個環境名稱作爲參數;然後
  2. 依次執行基準安裝腳本和每個修補程序腳本。

該批處理文件應自動執行後面添加的任何附加修補程序。

從本質上講,我需要做沿着此線的東西:

for %%_ in (1.3\**\GeneratedScripts\%%1\FullInstall.cmd) do cal %%_ 

但是我不知道通配符系統豐富,足以讓這個,因爲我沒有得到任何匹配的**目錄通配符。

例如,與參數「兩個」需要執行下面的腳本調用,依次是:

\1.3\Baseline\GeneratedScripts\Two\FullInstall.cmd 
\1.3\Patches\Patch1\GeneratedScripts\Two\FullInstall.cmd 
\1.3\Patches\Patch2\GeneratedScripts\Two\FullInstall.cmd 
\1.3\Patches\Patch3\GeneratedScripts\Two\FullInstall.cmd 

回答

2

這將執行基於參數中的子文件夾中的所有* .cmd文件的:

for /r 1.3\ %%X in (GeneratedScripts\%1\*.cmd) do call "%%X" 
+0

啊太棒了。閱讀「for」文檔時,我錯過了「/ r」開關。 – 2009-05-06 16:13:21

0

根據我的經驗,%1替換在目錄名稱中起作用。

這應該工作:

InstallEnvironment.bat:

 
\1.3\Baseline\GeneratedScripts\%1\FullInstall.cmd 
\1.3\Patches\Patch1\GeneratedScripts\%1\FullInstall.cmd 
\1.3\Patches\Patch2\GeneratedScripts\%1\FullInstall.cmd 
\1.3\Patches\Patch3\GeneratedScripts\%1\FullInstall.cmd 

編輯此批處理文件,以便添加額外的補丁,和它的作品。如果你想在後臺運行一個批處理文件,使用一個VBS文件在後臺運行該批處理文件,而不是

 
call InstallEnvironment.bat %1 
call InstallEnvironment.bat %2 
0

:如果您需要在多個目錄中運行的批處理文件,創建另一個批處理文件。 下面是代碼:

的CreateObject( 「Wscript.Shell」)運行 「」 「」 & Wscript.Arguments(0)& 「」 「」,0,假

保存此正是因爲看不見。 vbs(或其他),然後再創建另一個批處理文件,它將調用你的批處理文件在後臺運行它。 爲第二批文件中的代碼是:

的wscript.exe「invisible.vbs」「Your_Batch_File.bat」

然後運行第二批處理文件。

注意:應該在您的計算機上啓用WSH,並且invisible.vbs文件和第二個批處理文件應位於同一個文件夾中。如果不是那麼你可以給第二批處理文件的腳本中的invisible.vbs文件的完整路徑。