0

I am a windows batch screen noob. So I need to write a script that does this:

pushd \\network.com\shared\folder\201501
copy resume*.zip c:\temp\

Where the "201501" is updated to 201502, 201503, etc for each iteration. I can obviously just write out 12 of the same lines of the same thing, but I want to learn looping syntax better.

I know i can write a loop with

for /l %x in (1, 1, 12) do (
)

But I'm not sure how to make the "201501" a variable within that path string, that changes with the integer, and i don't know how to make it handle "01" vs "12" issue either. (Ie: 201501 --> 2015012 instead of 201512)

Can anyone help me?

2 Answers 2

2

RGuggisberg's answer is perfectly valid. Just to extend it for several years (might be your next question):

setlocal enabledelayedexpansion
for /L %%y in (14,1,16) do (
  for /L %%m in (1,1,12) do (
    REM add a leading zero:
    set "month=0%%m"
    REM take the last two digits from month:
    echo 20%%y!month:~-2!
    pushd "\\network.com\shared\folder\20%%y!month:~-2!"
    copy "resume*.zip" "c:\temp\"
    popd
  )
)
Sign up to request clarification or add additional context in comments.

Comments

2

This will get you started. Note that you use %x from a CMD prompt and %%x in a bat file. I used L instead of l because l looks too similar to a 1.

@echo off
for /L %%x in (201502, 1, 201512) do echo(%%x
pause

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.