.BAT file to loop through numbers - Need to add 0 to numbers less than 10 -
i have number of .bat files opening program , finding specific instance ran everyday. instance timestamped , changes everyday. having .bat file run through everynumber looking instance. format yyyymmddhhmmss.
from site have .bat file finds previous business day. have looping through numbers
the problem if number less 10, needs have 0 in front of it: 01,02,03,04 etc... way .bat file spits out, though, 1,2,3 etc...
here code have far:
for /l %%g in (3,1,9) ( /l %%h in (0,1,59) ( if %%h lss 10 set %%h=0%%h echo %prevbusday%0%%g%%h ) ) timeout /t 60 the first line loops through hours (3 9)
nested formula loops through minutes (0 59)
you can't modify %%h directly. have set "variable=%%h" , use delayed expansion retrieve !variable!. long you're setting variable anyway, use variable substrings. prepend 0 everything, use rightmost 2 digits.
setlocal enabledelayedexpansion /l %%g in (3,1,9) ( /l %%h in (0,1,59) ( set "h=0%%h" echo %prevbusday%0%%g!h:~-2! ) ) timeout /t 60
Comments
Post a Comment