Solved Batch file for Folder Creation in Specific Date Format

July 19, 2012 at 18:42:47
Specs: Windows 7 Professional
I need to create a batch file that will create directory based on the current date in the following format YYYY-MM-DD.

My computer's date format is currently set to DD/MM/YYYY.

Any ideas?


See More: Batch file for Folder Creation in Specific Date Format

Report •


#1
July 19, 2012 at 23:17:33
✔ Best Answer
@echo off & setlocal
for /f "tokens=1-4 delims=/ " %%a in ("%date%") do call :redate %%a %%b %%c %%d
goto :eof
:redate
if "%4" neq "" shift
set d8out=%3-%2-%1
echo %d8out%
md %d8out%
:end
not sure if your system put dofweek first like mine does, so i adds da insurance.

Report •

#2
July 19, 2012 at 23:24:42
Hi nbrane

Thanks for the reply, but it doesn't seem to be working. I copy and pasted your script into a batch file and nothing happens when I run it.


Report •

#3
July 19, 2012 at 23:31:41
my bad! Sorry, left : off of call redate, should be: call :redate. amended script in my first post to reflect.

Report •

Related Solutions

#4
July 19, 2012 at 23:38:19
Still no luck. I am newbie when it comes to script. So I have basically opened up notepad, pasted the following:

 @echo off & setlocal
for /f "tokens=1-4 delims=/ " %%a in ("%date%") do call :redate %%a %%b %%c %%d
goto :eof
:redate
if "%4" neq "" shift
set d8out=%3-%2-%1
echo %d8out%
:end
 

Saved it as script.bat. Then double-clicked the file. A Command Prompt window pops up briefly, but no folder. Am I doing something wrong?


Report •

#5
July 19, 2012 at 23:53:24
No, I am. You have correctly copied the script, but the script doesn't create the directory. I'll amend again to fix that. I just had script echo the reformatted date.
See my post again, just add the one line: md %d8out% where you see it.
(note: this does NOT take into account full machine/path qualifications, add those as needed.)
If you want the dir to have other info, put it into the script (f/e):
md xxx\yyy\direct1_%d8out%
to put it into the path xxx\yyy, and name it
direct1_2012-7-20

Report •

#6
July 19, 2012 at 23:54:22
if the %DATE% is DD/MM/YYYY

@echo off & setLocal enableDELAYedeXpansioN
echo md !D:~6!-!D:~3,2!-!D:~0,2!


====================================
Life is too important to be taken seriously.

M2


Report •

#7
July 19, 2012 at 23:57:04
I gotta think faster. Or type faster.


====================================
Life is too important to be taken seriously.

M2


Report •


Ask Question