Tuesday, January 8, 2008

Batch program to copy file with Date & Time - Archiving

Recently was looking for a simple batch file to archive some of my file with date and time stamp added to it. Compiled a simple script to do the job and it looks like:

d:

Set Source="D:\mySourcePath"
Set Target="D:\myTargetPath"
Set Date=%date:~10,4%%date:~4,2%%date:~7,2%
Set Time=%time:~0,2%%time:~3,2%

REM myFile.log
copy /y %Source%\myFile.log %Target%\myFile_%Date%_%Time%.log
Del /q %Source%\myFile.log

Love coding!

No comments: