.BAT文件循环编号 - 需要添加0到小于10的数字 [英] .BAT file to loop through numbers - Need to add 0 to numbers less than 10
问题描述
我有一些.bat文件正在打开一个程序,并找到一个每天运行的特定实例。这个实例有时间戳,每天都会改变。所以我有.bat文件运行通过everynumber查找该实例。格式是YYYYMMDDHHMMSS。
从这个网站我已经有一个.bat文件,发现前一个工作日。我甚至有循环的数字
问题是如果数字小于10,它需要在它前面有一个0:
01 ,02,03,04 etc ...
.bat文件吐出来的方式是1,2,3等...
这里是我已经到目前为止的代码:
对于/ L %% G IN(3,1,9)DO (
For / L %% H IN(0,1,59)DO(
如果%% H LSS 10 SET %% H = 0 %% H
ECHO%prevbusday%0% %G %% H
)
)
超时/ t 60
第一行循环遍历小时(3至9)
嵌套公式循环遍历分钟(0至59)
你不能直接修改 %% H
。您必须设置variable = %% H
,并使用延迟扩展来检索!variable!
。只要你设置另一个变量,只要使用可变的子字符串。预先设置为零,然后使用最右边的两位数字。
$ b
setlocal enabledelayedexpansion
对于/ L %% G IN(3,1,9)DO(
For / L %% H IN(0,1,59)DO(
seth = 0 %% H
ECHO%prevbusday%0 %% G!h:〜-2!
)
)
timeout / t 60
I have a number of .bat files that are opening a program and finding a specific instance that is ran everyday. This instance is timestamped and changes everyday. So I am having the .bat file run through everynumber looking for that instance. The format is YYYYMMDDHHMMSS.
From this site I already have a .bat file that finds the previous business day. I even have it looping through the numbers
The problem is if the number is less than 10, it needs to have a 0 in front of it:
01,02,03,04 etc...
The way the .bat file spits it out, though, is 1,2,3 etc...
Here is the code I have so far:
For /L %%G IN (3,1,9) DO (
For /L %%H IN (0,1,59) DO (
If %%H LSS 10 SET %%H=0%%H
ECHO %prevbusday%0%%G%%H
)
)
timeout /t 60
The first line loops through the hours (3 to 9)
The nested formula then loops through the minutes (0 to 59)
You can't modify %%H
directly. You have to set "variable=%%H"
and use delayed expansion to retrieve !variable!
. As long as you're setting another variable anyway, just use variable substrings. Prepend a zero to everything, then use the rightmost two digits.
setlocal enabledelayedexpansion
For /L %%G IN (3,1,9) DO (
For /L %%H IN (0,1,59) DO (
set "h=0%%H"
ECHO %prevbusday%0%%G!h:~-2!
)
)
timeout /t 60
这篇关于.BAT文件循环编号 - 需要添加0到小于10的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!