2016-06-07 45 views
0

所以我想調用一個目錄中的所有文件,其中包含一個變量,稍後再回應該變量。我遇到的唯一問題是它不會回顯變量。它只是說ECHO關閉。我的for循環沒有在另一個文件中顯示一個變量

這是我目前的代碼。

// THIS IS MY FOR LOOP. 
@echo off 

:Message 
for %%i in (Soemthing\*.bat) do (
    call %%i 
    echo %Message% 
) 

pause 
exit 

// THIS IS THE FILE I WANT IT TO CALL. 
@echo off 

set %Message%=Some message here. 
+2

需要[延遲膨脹(http://stackoverflow.com/a/30284028/2152082)。你的'set'命令是錯誤的:'set「message =這裏有一些消息」' – Stephan

+0

不,不起作用。仍然表示ECHO關閉。 –

+0

@Stephan它不起作用。 –

回答

1
> type a.bat 
@echo off 
setlocal enabledelayedexpansion 
:Message 
for %%i in (b.bat) do (
    call %%i 
    echo !Message! 
) 
pause 

> type b.bat 
set "Message=Some message here." 

> a.bat 

Some message here. 
Drücken Sie eine beliebige Taste . . . 

> 
+0

我不想讓它調用b.bat,我想改爲(* .bat),以便調用每個文件。 –

+0

這就是所謂的例子。向你展示它是如何工作的。當然,你可以用'Soemthing \ *。bat'替換'b.bat',它會調用該文件夾中的每個bat文件。 – Stephan

相關問題