Create a folder using current date as the name...

Posted on 2005-05-02
Last Modified: 2011-09-20
This question has probably been ask a thousand times but here goes one more time...

 I would to use a bat file to create a folder that uses the current date as the name of the folder, IE. something like or close to "5-2-2005". I tried using md "%date%", but I get a folder called "Mon 05" containing a subfolder called "02" and containing yet another subfolder called "2005". I know very little about DOS scripting so I have searched high and low & have come up with nothing. So, once again I will ask for your help.

Question by:Ryan Bennett
    LVL 95

    Accepted Solution

    Here's a script that should give you the flexibility to do this as you want it to appear:

    Set MM=%date:~4,2%
    Set DD=%date:~7,2%
    Set YYYY=%date:~-4%
    MD %MM%-%DD%-%YYYY%

    Of course, you could also use:
    MD %date:~4,2%-%date:~7,2%-%date:~-4%

    LVL 95

    Expert Comment

    by:Lee W, MVP
    To explain a little further:

    REM set the variable MM to the value of the %date% variable, but only take
    REM the two characters starting at the 4th character (and remember the first
    REM character is character 0)
    Set MM=%date:~4,2%

    REM Like above, only take the 2 characters starting at the 7th character
    Set DD=%date:~7,2%

    REM Like above, only take the last 4 (-4) characters from %date%
    Set YYYY=%date:~-4%
    MD %MM%-%DD%-%YYYY%

    Author Comment

    by:Ryan Bennett
    I guess it helps if you know what you're doing. Exactly what I've been trying to do.

     Thanks a bunch,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
    Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now