Monday, November 16, 2009

Using DOS Batch commands to create release folder with DateTime

In my current endeavor I have a solution that contains 3 setup projects that each has a distinct purpose within the overall scheme of things. When I build the solution I'd like to be able to have all 3 setup projects' output all grouped together in one folder whose name reflects the unique datetime (to the second). That way I can uniquely identify at a later date the releases that get built. Here's how I do it with a DOS batch file.

for /F "tokens=1-4 delims=/- " %%A in ('date/T') do set DATE1=%%D%%B%%C
for /F "tokens=1-4 delims=:., " %%a in ('time/T') do set TIME1=%%c%%a%%b
set "dt1=%DATE1:~0,8%%TIME1:~0,1%%TIME1:~2,4%"
set releasedir=MySoftware_%dt1%_Release
z:
cd \All_Customer_Releases
md %releasedir%
cd %releasedir%
md Build1
cd Build1
c:
cd "C:\Documents and Settings\alex\My Documents\Visual Studio 2008\Projects\SolutionRoot"
cd "Setup1\Debug"
copy *.* z:
z:
cd ..
md Build2
cd Build2
c:
cd ..\..
cd "Setup2\Debug"
copy *.* z:
z:
cd ..
md Build3
cd Build3
c:
cd ..\..
cd "Setup3\Debug"
copy *.* z:


Please note that I changed the solution name and the names of the 3 projects to protect my customer's privacy.

I also include this batch file in the root folder of the solution where the .sln file is located. That way its tracked like all the rest of my source files in TFS Version Control.

No comments:

Post a Comment