For next loop

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
bgane
Posts: 1
Joined: 24 May 2018 15:23

For next loop

#1 Post by bgane » 24 May 2018 15:33

I need to create a for next loop that will do the following.

We have predefined variables on our Server for HPMONTH, HPYEAR for example,

HPMONTH can be 01 - 12 for January through December
HPYEAR is in the format (for this year) 2018

I need to copy reports each month to folders that have the month in name (i.e. January - December) so the HPMONTH which is a number needs to be put into another variable like (MONTH) so that Jan is 01, Feb is 02, etc.
01 January Monthend Production for 2018
02 February Monthend Production for 2018

We have a PREFIX on the folder names for 01, 02, 03 only so that when the folder names are sorted, they use that number to sort because otherwise January will not be first if you know what I mean. The for next loop only needs to assign to the variable MONTH so that when HPMONTH is 01, the variable MONTH will be assigned the name JANUARY, for February, the HPMONTH has the number 02 so then the for next loop should assign to the variable MONTH, the name FEBRUARY, etc. Not hard but have never done it myself.

Brian

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: For next loop

#2 Post by penpen » 26 May 2018 14:25

Your description is missing some details (where to find the files to copy, where to copy to, so i assume all could be found in the actual directory), so the following might help you:

Code: Select all

@for %%a in ("*") do @for /d %%b in ("%HPMONTH%*") do @copy "%%~a" "%%~b"
penpen

Post Reply