How to create a folder with name as current date in batch (.bat) files

前端 未结 24 1224
被撕碎了的回忆
被撕碎了的回忆 2020-12-08 02:26

I don\'t know much about windows .bat file syntax. My simple requirement is to create a folder at a specific location with name as current date. I tried searching this on go

24条回答
  •  失恋的感觉
    2020-12-08 02:50

    I had a problem with this because my server ABSOLUTELY had to have its date in MM/dd/yyyy format, while I wanted the directory to be in YYYY-MM-DD format for neatness sake. Here's how to get it in YYYY-MM-DD format, no matter what your regional settings are set as.

    Find out what gets displayed when you use %DATE%:

    From a command prompt type:

    ECHO %DATE%
    

    Mine came out 03/06/2013 (as in 6th March 2013)

    Therefore, to get a directory name as 2013-03-06, code this into your batch file:

    SET dirname="%date:~6,4%-%date:~0,2%-%date:~3,2%"
    mkdir %dirname%
    

提交回复
热议问题