【问题标题】:Why do my .bat always loses its variable after the lengthy commands为什么我的 .bat 在冗长的命令之后总是丢失它的变量
【发布时间】:2012-08-05 16:21:22
【问题描述】:

这是我遭受逆境的 .bat。让我们将其命名为b.bat

set loopnum=%1
set url=%2
del "%TEMP%\selectortemp.txt"
del "%TEMP%\selectortemp2.txt"
for /r %loopnum% %%i in (\*.*) do echo %%~ni%%~xi>>"%TEMP%\selectortemp.txt"

echo %loopnum%
pause

set count=0
for /f "usebackq delims=" %%a in (%TEMP%\selectortemp.txt) do set /a count+=1

set /a count2=1
:looping

for /f "tokens=1,2 delims==" %%a in (%config%) do (if %%a==url set url=%%b)

set /p firstline=<"%TEMP%\selectortemp.txt"

del "%url%\%firstline%"

echo "%firstline%"
pause

for /f "skip=1 tokens=*" %%A in (%TEMP%\selectortemp.txt) do echo %%A>>"%TEMP%\selectortemp2.txt"
del "%TEMP%\selectortemp.txt"
rename "%TEMP%\selectortemp2.txt" "selectortemp.txt"

if %count2%==%count% goto endlooping
set /a count2+=1
goto looping
:endlooping

起初,我这样称呼它:

for /l %%i in (0,1,3) do (call b.bat %%i C:\testing)

【问题讨论】:

  • “丢失变量”是什么意思?请多描述一下你的问题。 (使用编辑按钮向您的帖子添加更多信息。下次,请使用{} 代码按钮为您的代码/批处理文件。)
  • sry... 我发现 .bat 实际上不会丢失它。我的意思是它不会成为一个空变量。但是,这是因为我的循环很差,以至于 .bat 崩溃了。下次我将使用 {}。谢谢。

标签: file variables batch-file


【解决方案1】:

您的问题不是很具体。 我假设你的意思是你的变量在 for 循环中丢失了它们的内容。

你需要写 !a!代替%。但是你不能用 for 循环中使用的变量来做到这一点。 !!a 是不可能的。

请务必启用延迟扩展。

这里有一些关于 enabledelayedexpansion 的信息:SS64

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-01
    • 2011-09-15
    • 2016-01-22
    • 2014-08-23
    • 1970-01-01
    • 2012-06-05
    相关资源
    最近更新 更多