Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 删除文件计数器工作,但给出随机数_Batch File_Cmd - Fatal编程技术网

Batch file 删除文件计数器工作,但给出随机数

Batch file 删除文件计数器工作,但给出随机数,batch-file,cmd,Batch File,Cmd,我制作了一个计数器从minecraft savelevel.dat_old文件中删除,如下所示: @echo off :asd :E if not exist level.dat_old goto asd SETLOCAL ENABLEDELAYEDEXPANSION @echo off set /a counter=1 for /r %%f in (*) do ( set /a counter=!counter!+1 if exist level.dat_old del leve

我制作了一个计数器从minecraft save
level.dat_old
文件中删除,如下所示:

@echo off
:asd
:E
if not exist level.dat_old goto asd
SETLOCAL ENABLEDELAYEDEXPANSION

@echo off

set /a counter=1

for /r %%f in (*) do (
  set /a counter=!counter!+1
  if exist level.dat_old del level.dat_old
  if exist level.dat_old echo Level dat deleted !counter! times!
  
)
goto asd
正确删除文件,但deleter计数器会给出疯狂的随机数,这会打印:

设置/a计数器=!柜台+1
如果存在level.dat_old del level.dat_old&set/a计数器+=1

生成“疯狂数字”是因为您的代码为每个文件的计数器递增。也可以更传统地从零开始计数,而不是从1开始

Level dat deleted 2 times
Level dat deleted 2 times
Level dat deleted 36 times
Level dat deleted 84 times