Monday 6 May 2013

Create a TimeStamp Folder in windows - Batch script Backup

You can write a script to create a folder in Windows
Open the Command Prompt and type echo %date% to get todays date.
If we wanted to get the current year we can start 4 from the end, and 4 in length.
echo %date:~-4,4%
For the month we start with 7
echo %date:~-7,2%
For the day we start with 10
echo %date:~-10,2%
To create a backup using the batch script use this:
set TIMESTAMP=%DATE:~-10,2%-%DATE:~-7,2%-%DATE:~-4,4%

@echo TIMESTAMP=%TIMESTAMP%
xcopy C:\BACKUPS\*.* D:\BackupFolder\%TIMESTAMP%\ /e /i /y
This will copy everything on the folder Backups from C Drive to BackupFolder on D Drive with a time stamp folder.