Wednesday, January 6, 2021

MS-DOS Batch File Copy with Date-Stamped Name

 I created a batch file to copy the compiled exe of a Winform app, and then backup the source code to an archive folder named with the date/time stamp:


@echo off

cls

echo Date format = %date%

echo.

echo Time format = %time%

echo.

set Timestamp=%date:~10,4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%


set folder=_versions\wiki%Timestamp%\

xcopy app %folder% /s /e 


copy app\Wiki\Wiki\obj\Debug\Wiki.exe _release\Wiki.exe


I got a lot of help for this from this StackExchange entry. I found this Steve Jansen article useful also.