批处理变量不递增!

发布于 2024-11-09 08:18:26 字数 1160 浏览 0 评论 0原文

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 没有增加

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 is not getting incremented

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱情眠于流年 2024-11-16 08:18:26

你需要延迟扩展来解决这个问题。
由于在解析块时所有百分比变量都会扩展,因此它们的值似乎没有变化。

通过延迟扩展,变量在执行时扩展。

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

You need the delayed expansion to solve this.
As all percent variables expands while a block is parsed, their values seems to be unchanged.

With delayed expansion the variables are expanded at execution time.

setlocal EnableDelayedExpansion
set count=0
(
   set /a count+=1
   echo %count% fails
   echo !count! works
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文