Windows batch, How to rename a directory to date and time with seconds

batchcommand linerenamewindows

Windows batch,
How to rename a directory to date and time with seconds

Current drive and directory is S:\1 = a backup.

via batch, How to automate, How to rename a directory, not a file?
something like — Rename S:\1 S:\20171022_131459

2017 year
10 October
22 day
13 hours
14 minutes
59 seconds

Below was does at the command line with one %
on a file named hope.txt, not a directory

ren hope.txt 20171022.txt

.

for /f "tokens=1-4 delims=- " %d in ("%date%") do rename "hope.txt" %d%e%f.txt

and in part 2 (time)
Seconds are missing in name and
it is not a directory, but, it does a file
named hope.txt with hours and minutes.

rename "hope.txt" 1314.txt 

.

for /f "tokens=1-2 delims=: " %G in ("%time%") do rename "hope.txt" %G%H.txt

Best Answer

I think this does what you are looking for:

for /f "tokens=2-7 delims=/:. " %a in ("%date% %time%") do ren dir1 %c%ab%b_%d%e%f

The output looks like this:

ren dir1 201710b22_201108

In a batch file you need extra % so this line becomes:

for /f "tokens=2-7 delims=/:. " %%a in ("%date% %time%") do ren dir1 %%c%%ab%%b_%%d%%e%%f
Related Question