0

Note : question regarding Windows shell

I want to write a simple batch script to create a folder name is it does not exist with the system date as the name of the folder.

Current system date :

$ date /t
Sat 09/10/2011

I want the folder name to be created in the format dd-mm-yy and in the C:\ dir 10-09-11

First I tried according to this (Link to microsoft doc for date)

$ date dd-mm-yy /t

this was supposed to get me the date in the format I wanted but instead it just returned the same format as above.

To make the dir I tried

$ mkdir "%date dd-mm-yy /t%"

and many such variations with no success.

I just want to create a folder name with the system date in format dd-mm-yy, It would be good if I can have the folder name in a variable as I need to use it to copy files into this folder later in the batch script

Can anyone help me out?

1

1 Answer 1

2

I once had a same problem. Windows shell is so weak :( My solution was to use substring.

set X=%DATE%
mkdir %X:~3,2%-%X:~,2%-%X:~8,2%

Note: DATE string is in language specific format that can only be changed in the regional setting of the control panel. So the substring parameter may have to be tweaked. For example I got 2011/09/10 for Japanese language.

REM for Japanese language setting
mkdir %X:~8,2%-%X:~5,2%-%X:~2,2%
1
  • Ya windows shell is so weak, and so much for the documented method. Your substring solution worked perfectly. Thanks.
    – Anand
    Commented Sep 10, 2011 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.