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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Legacy OS

From novice to tech pro — start learning today.