2011-05-23 218 views
1
SET /a _count = 1 

set /p drive=Please type drive name[C/D/E/F/..]?: 
echo Creating Directory %drive%:\AKI_Data_Feeds 
mkdir %drive%:\AKI_Data_Feeds 

for /f %%a in (companyList.txt) do (
echo Creating Directory %drive%:\AKI_Data_Feeds\%%a 
mkdir %drive%:\AKI_Data_Feeds\%%a 

for /f %%b in (branch1.txt) do (
echo Creating Directory %drive%:\AKI_Data_Feeds\%%a\%%b 
mkdir %drive%:\AKI_Data_Feeds\%%a\%%b 


if "%_count%"=="1" (

for /f %%c in (branch1_1.txt) do (
echo Creating Directory %drive%:\AKI_Data_Feeds\%%a\%%b\%%c 
mkdir %drive%:\AKI_Data_Feeds\%%a\%%b\%%c 

for /f %%e in (branch2.txt) do (
echo Creating Directory %drive%:\AKI_Data_Feeds\%%a\%%b\%%c\%%e 
mkdir %drive%:\AKI_Data_Feeds\%%a\%%b\%%c\%%e 
) 

) 

SET /a _count +=1 
echo %_count% 

) 
if "%_count%"=="2" (
for /f %%d in (branch1_2.txt) do (
echo Creating Directory %drive%:\AKI_Data_Feeds\%%a\%%b\%%d 
mkdir %drive%:\AKI_Data_Feeds\%%a\%%b\%%d 

for /f %%e in (branch2.txt) do (
echo Creating Directory %drive%:\AKI_Data_Feeds\%%a\%%b\%%c\%%e 
mkdir %drive%:\AKI_Data_Feeds\%%a\%%b\%%c\%%e 
) 

) 

SET /a _count +=1 

) 

) 
) 

echo Successfully created. 
pause 

_count是沒有得到增加批量變量不遞增!

+0

'command.com' /'cmd'是什麼? – 2011-05-23 13:20:11

+0

我正在運行在.bat文件 – 2011-05-23 13:21:01

+1

...在MS-DOS 3.3,Windows XP,Windows 98,FreeDos ..上? – 2011-05-23 13:22:32

回答

5

您需要延遲擴展解決這個問題。
由於所有百分比變量在解析塊時展開,因此它們的值似乎未發生變化。

隨着延遲擴展,變量在執行時被擴展。

setlocal EnableDelayedExpansion 
set count=0 
(
    set /a count+=1 
    echo %count% fails 
    echo !count! works 
) 
+0

任何參考! vs%使用率? – Zoso 2017-08-22 15:14:56