Monday, February 29, 2016

A Release batch file

Needed a batch file to create a release from a nuget package (probably works with a zip), creates an ISO 8601 date folder and copies the data there and replaces the permissions. It also needed a better way to get the local date as normal DOS date took region into account and caused errors.

set releasename=ClientName

FOR /f %%a in ('WMIC OS GET LocalDateTime ^| find "."') DO set DTS=%%a
set todaysdate=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%
echo %todaysdate%

FOR /F "delims=" %%i IN ('dir /b %releasename%*') DO set file=%%i

FOR %%i IN ("%file%") DO (
set filedrive=%%~di
set filepath=%%~pi
set filename=%%~ni
set fileextension=%%~xi

echo %filename%

SET releasedir=..\Releases\%todaysdate%\
mkdir %releasedir%
echo %releasedir%

ren %filename%.nupkg
move %releasedir%

set releasedirwithfilename=%releasedir%%filename%

unzip -d %releasedirwithfilename%

xcopy /E /Y BaseFiles\* %releasedirwithfilename%

icacls "%releasedirwithfilename%\*" /q /c /t /reset