【问题标题】:Incrementing variable not working递增变量不起作用
【发布时间】:2016-03-03 11:02:35
【问题描述】:
@echo off
FOR %%P IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO (
  IF EXIST %%P:\nul (
cls
SET /a count=%count%+1
dir /s /b %%P:\ |find /c "\" >NUMfiles.max
set /p "counter%count%"=<NUMfiles.max

del %%P:\apple.doc
del %%P:\orange.doc

dir /s /b %%P:\ |find /c "\" >NUMfiles.max
set /p "counter%count%%%P"=<NUMfiles.max
set /a "counter%%P"="counter%count%" - "counter%count%%%P"

  )
)

set /a finalcount="countera + counterb + counterc + counterd + countere +         counterf + counterg + counterh + counteri + counterj + counterk + counterl + counterm + countern + countero + counterp + counterq + counterr + counters + countert + counteru + counterv + counterw + counterx + countery + counterz"
ECHO Total Number of deleted files: %finalcount%

该程序正在扫描每个驱动器以删除 apple.doc 和 orange.doc,并在完成从所有驱动器中删除所有文件后,它会给出删除文件总数的总结果。

请帮忙。

【问题讨论】:

标签: variables batch-file increment


【解决方案1】:

你错过了好旧的SETLOCAL EnableDelayedExpansion。当使用在 FOR 循环中修改的变量时,您始终必须在脚本的开头添加 SETLOCAL EnableDelayedExpansion。此外,您必须使用!var! 而不是%var% 来处理循环修改的变量。应该是这样的。

【讨论】:

  • 你能帮我修改我的代码,而不是让我完全理解,因为我仍然有语法错误......希望没关系......
  • 不需要我让它工作。语法错误来自 set 命令中的“”。非常感谢你!!!
猜你喜欢
  • 2013-06-30
  • 2014-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多