2015-04-07 74 views
0

我有一个bat文件,将所有png文件重命名为data_文件。它开始从data_1data_2 ....我想从data_140data_141开始...用特定号码的bat文件重命名

如何做到这一点?

:: Renaming files 
for %%a in (*.png) do (
    set /a count+=1 
    set "fname=%%~a" 
    setlocal enabledelayedexpansion 
    ren "!fname!" data_!count!.png 
    endlocal 
) 
+3

有什么问题吗? '只需在'for'之前预置'count'变量即可。 – Stephan

+0

你不需要预设你的'count'变量。来自'help set':“如果指定了一个环境变量名称,但在当前环境中没有定义,那么[使用'/ A'开关]使用零值。” – indiv

+1

@indiv:我的意思是用'set count = 139'来预设它。对不起,我想,这很明显。 – Stephan

回答

0

我没有看到问题。 SET /A count+=1从count = 0开始,因为它尚未定义。如果你希望你的脚本在140开始只是做set count=139你进入循环之前:

:: Renaming files 
set count = 139 
for %%a in (*.png) do (
    set /a count+=1 
    set "fname=%%~a" 
    setlocal enabledelayedexpansion 
    ren "!fname!" data_!count!.png 
    endlocal 
) 
相关问题