Create Folder using YY-DD-MONTH format

Dineshdu

Disciple
How can I create a folder from command prompt in YY-MM-MONTH format by using batch file. For example, If I want to create a folder today, the name of the folder should be 13-03-April. Here is what I have came up with.

Code:
for /f "tokens=2,3,4 delims=/ " %%a in ('Date /t') do (
set month=%%a
set day=%%b
set year=%%c ) 
echo %year%-%day%-%month%
mkdir C:\%year%-%day%-%month%

The above code creates the folder as 2013 -03-04.
 
You are using the 'Date' command which is system/locale dependent so this batch file may not work on another computer or on your PC if someone changes the 'short date' format from 'Control Panel/Region and Language Settings'

Instead of 'Date /t' try using the WMIC command mentioned in the first answer here.
http://stackoverflow.com/questions/5594121/batch-script-date-into-variable


In your code, the date command will never return names of the month so you have to work around it. The batch file below does what you wanted using 'Date /t' and a pseudo switch-case.


Code:
for /f "tokens=2,3,4 delims=/ " %%a in ('Date /t') do (
set month=%%a
set day=%%b
set year=%%c)
 
GOTO CASE_%month%
:CASE_01
    set monthalpha=January
    GOTO END_SWITCH
:CASE_02
    set monthalpha=February
    GOTO END_SWITCH
:CASE_03
    set monthalpha=March
    GOTO END_SWITCH
:CASE_04
    set monthalpha=April
    GOTO END_SWITCH
:CASE_05
    set monthalpha=May
    GOTO END_SWITCH
:CASE_06
    set monthalpha=June
    GOTO END_SWITCH
:CASE_07
    set monthalpha=July
    GOTO END_SWITCH
:CASE_08
    set monthalpha=August
    GOTO END_SWITCH
:CASE_09
    set monthalpha=September
    GOTO END_SWITCH
:CASE_10
    set monthalpha=October
    GOTO END_SWITCH
:CASE_11
    set monthalpha=November
    GOTO END_SWITCH
:CASE_12
    set monthalpha=December
    GOTO END_SWITCH
:END_SWITCH
echo %year%-%day%-%monthalpha%
mkdir C:\%year%-%day%-%monthalpha%

-edit-

to get a two digit year instead of curernt four digit value, replace %year% with %year:~2,2% in the last two statements
 
Back
Top