3

I have a file at:

c:\source\hello.txt

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

c:\backups\source\????\hello.txt

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.

1 Answer 1

4

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .