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

前端 未结 24 1277
被撕碎了的回忆
被撕碎了的回忆 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:33

    the expression %date:~p,n% returns n number of characters from position p in the date string.

    if my system date string is Mon23/11/2015

    the command %date:~1,3% returns the value Mon

    the command %date:~10,4% returns the value 2015

    and in conjunction with the md (or mkdir) command

    the command md %date:~10,4%%date:~7,2%%date:~4,2% makes a directory named 20151123

    likewise if your date string in in the format Monday, 23/Nov/2015

    the command md %date:~16,4%%date:~12,3%%date:~9,2% makes a directory named 2015Nov23

    If you accidentally return characters from the date string that are not allowed in folder names or use invalid values for p and n you will get an error. Additionally if you return values that include \ this may create a folder within a folder.

提交回复
热议问题