在FORLOOP中递增计数器变量 [英] incrementing a counter variable inside a FORLOOP

查看:69
本文介绍了在FORLOOP中递增计数器变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当FOR循环再次遍历变量时,为什么变量"number"没有增加?

why is the variable "number" not increasing when the FOR loop goes over it again?

setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (input.txt) do (
set /a N+=1
set /a number=!number!+1
echo  %%a !number!.jpg >output.txt
)

推荐答案

首先,我不建议您在使用文件名时启用变量扩展,仅当您真正知道启用延迟扩展的含义时才使用它,收益(提高速度)和负面(缺少角色).

First of all I don't recommend you to enable expansion of variables when you are working with filenames, use it only if you really know what means enabling the delayedexpansion, the benefits (improved velocity) and the negatives (missing characters).

此外,您正在为变量"N"分配一个值,但是您不使用该变量.

Also you are assigning a value for the variable "N" but you don't use that var.

这是代码:

@echo off

(for /f "usebackq tokens=* delims= " %%a in ("input.txt") do (
    Set /A Number+=1
    Call Echo %%a %%number%%.jpg
))>"Output.txt"

Pause&Exit

这篇关于在FORLOOP中递增计数器变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆