开发者

How do I create a directory with the system date in window shell batch script

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?


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%
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜