簡體   English   中英

增量變量不起作用

[英]Incrementing variable not working

@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,從所有驅動器中刪除所有文件后,它將為我提供刪除的文件總數的總結果。

請幫忙。

您缺少很好的舊SETLOCAL EnableDelayedExpansion 使用在FOR循環內修改的變量時,必須始終在腳本的開頭添加SETLOCAL EnableDelayedExpansion 此外,您必須使用!var!處理循環修改的變量!var! 而不是%var% 應該是這樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM