Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a file at:


That I want to backup as I modify it often, to here:


How can I create such a .bat file to do this?

I want the script to somehow create a sub-folder with the current date and time, so that when I view the folders it will be ordered so I can get the latest or go back in time easily.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Getting a main idea from here:

@echo off
set hh=%time:~-11,2%
set /a hh=%hh%+100
set hh=%hh:~1%
set dateseed=%date:~10,4%%date:~4,2%%date:~7,2%_%hh%%time:~3,2%%time:~6,2%

if not exist "c:\backups\source\%dateseed%" mkdir "c:\backups\source\%dateseed%"
cd "c:\backups\source\%dateseed%"
copy "c:\source\hello.txt" .

It will create a folder named yyyymmdd_hhmmss (hh in 24-hours format).

You can also check copy /? for further options.

If you're working with files or folders other than on C: make sure you add a line to change to that drive before attempting to make a folder or change dir into one.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.