Batch file create folder with date

I created a batch file to move my exports based on their name but I need to see if the batch can create the folder based on the month prior (ex: 2013-08 folder created when reports ran after month end on 09/05).  The reports are always run after the month is over  but the data is the previous month's.

Export folder contains:
Report A Burger Don
Report B Burger Don
Report C Burger Don
Report A King Mac
Report B King Mac
Report C King Mac
Report A Family Fish
Report B Family Fish
Report C Family Fish

move /-y "\\slcfile\shared\Exports\*Burger Don*.*" "\\slcfile\shared\Reports\BD\2013-08"
move /-y "\\slcfile\shared\Exports\*King Mac*.*" "\\slcfile\shared\Reports\King\2013-08"
move /-y "\\slcfile\shared\Exports\*Family Fish*.*" "\\slcfile\shared\Reports\FFish\2013-08"
Who is Participating?
SterlingMcClungConnect With a Mentor Commented:
You can use substring expansion to grab the information that you want:

set currentMonth = %date:~-7,2%

Open in new window

On my computer this grabs the month from the date variable "24/09/2013".  The -7 indicates to start taking characters from the 7th to the last character and the ,2 means take 2 characters.  You can use this same technique to grab the 4 digit year.  Realize that you will need to adjust based on your regional settings.

You can then use batch math, using set /a, to subtract one from the month.  However, batch math, using set /a, interprets leading zeroes as octal numbers, so we must first get rid of those:

if %currentMonth:~0,1%==0 set currentMonth=%currentMonth:~-1%
set /a lastMonth=%currentMonth% - 1

Open in new window

If your regional settings don't use a leading zero for dates less than 10, then you will have to check for a slash(or whatever you are using for a delimiter in your dates):

if %currentMonth:~0,1%==/ set currentMonth=%currentMonth:~-1%

Open in new window

Combine this information with the commands you listed and you should be able to do what you want.
NNiicckkAuthor Commented:
I apologize for the delay in responding.

Currently, I created a 2013-08 folder in every Client's folder to run the batch.  As this can be tedius with a larger number of Clients, I was trying to have the system create the folder when exporting.  Based on the previous month. (if possible)

So, for October 3, I would like to have folder created as 2013-09.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.