cmd - Writing a loop & variable for a windows batch script -
i windows batch screen noob. need write script this:
pushd \\network.com\shared\folder\201501 copy resume*.zip c:\temp\
where "201501" updated 201502, 201503, etc each iteration. can write out 12 of same lines of same thing, want learn looping syntax better.
i know can write loop with
for /l %x in (1, 1, 12) ( )
but i'm not sure how make "201501" variable within path string, changes integer, , don't know how make handle "01" vs "12" issue either. (ie: 201501 --> 2015012 instead of 201512)
can me?
rguggisberg's answer valid. extend several years (might next question):
setlocal enabledelayedexpansion /l %%y in (14,1,16) ( /l %%m in (1,1,12) ( rem add leading zero: set "month=0%%m" rem take last 2 digits month: echo 20%%y!month:~-2! pushd "\\network.com\shared\folder\20%%y!month:~-2!" copy "resume*.zip" "c:\temp\" popd ) )
Comments
Post a Comment