I want to create a folder with specific name in a directory and if it already exists, it should create a folder with the same name but adding an index at the end. For instance creating folder 2017-07-31 in D:\path and if it exists, creates 2017-07-31_1 and if it still exists, creates 2017-07-31_2 etc.
set foldername=%DATE:~-4%-%DATE:~3,2%-%DATE:~0,2% set path=D:\path