本文介绍了一批循环增值ENABLEDELAYEDEXPANSION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个简单的批处理文件,从所有文件做出7zip的-档案在它的目录中。

我要7zip的,档案馆得到这样的 a01.7z a02.7z a03.7z ...

显然,在递增值间歇for循环是不容易的。

在SETLOCAL ENABLEDELAYEDEXPANSION解决方案并不在我的电脑上工作(窗口10,64位)

有人建议把触发递增code在子程序:

 设置/计数器= 0
对于%% i的(*。*)做(
    拨打:PASS2
    转到:续
    :PASS2
        集/计数器=%计数器%+ 1
        GOTO:EOF
    :续
        C:\\ Program Files文件\\的7-Zip \\ 7z.exe一个一个柜台%%%%我

这不起作用,因为不知何故DOS不明白最后的我%%了,只是输出%i的。

请教我如何做一个for循环中批次的计数器。


解决方案

这是生成两个位号码最简单的方式,用左零:

 关闭@echo
SETLOCAL EnableDelayedExpansion集/计数器= 100
对于%% i的(*。*)做(
   集/计数器+ = 1
   C:\\ Program Files文件\\的7-Zip \\ 7z.exe一个计数器:〜!1! %%一世

I'm trying to make a simple batch-file to make 7zip-archives from all the files in it's directory.

I want the 7zip-archives to get names like a01.7z, a02.7z, a03.7z...

Apparently incrementing a value in a batch-for-loops isn't easy.

The setlocal ENABLEDELAYEDEXPANSION solution doesn't work on my computer (windows 10, 64-bit)

Someone suggested putting the increment-code in a subroutine:

set /a counter=0
for %%i in (*.*) do (
    call :pass2
    goto :cont
    :pass2
        set /a counter=%counter%+1
        goto :EOF
    :cont
        "c:\Program Files\7-Zip\7z.exe" a a%counter% "%%i"
)

This doesn't work because somehow DOS doesn't understand the final "%%i" anymore and just outputs "%i".

Please teach me how to make a for-loop in batch with a counter.

解决方案

This is the simplest way to generate two-digits numbers, with a left zero:

@echo off
setlocal EnableDelayedExpansion

set /A counter=100
for %%i in (*.*) do (
   set /A counter+=1
   "c:\Program Files\7-Zip\7z.exe" a a!counter:~1! "%%i"
)

这篇关于一批循环增值ENABLEDELAYEDEXPANSION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-13 04:35