I have the following batch file which concatenates all of the files in a folder that have a .sql ending.
set func=%~dp0%Stored Procedures\*.sql
for %%i in (%func%) do type "%%i" >>InstallScript.sql
We use SVN as our repository, and we're using branching. Currently the script concatenates all the .sql files, even the ones that haven't changed. I'd like to change it so it only concatenates files that have been modified and/or created after the branch was created. We can do that by looking at the datetime on the .svn folder in each folder (there's a Stored Procedure, View, Function subfolders). But I don't know how to do that with batch files.
Ideally something like this(pseudo code):
set func=%~dp0%Stored Procedures\*.sql
set branchDateTime=GetDateTime(%~dp0%.svn) <- Gets the datetime when the .svn folder was created
for %%i in (%func%)
{
if(%%i.LastModifiedOrCreated > branchDateTime)
do type "%%i" >> InstallScript.sql
}
Thanks to Doc Brown, I ended up getting this(for anyone that needs something similar):
@echo off
cls
echo --Install Script Generated For MMH Database %DATE% %TIME% > InstallScript.sql
set branch=%~dp0.svn
for %%i in (%branch%) do set SvnFileDate=%%~ti
set year=%SvnFileDate:~8,2%
set month=%SvnFileDate:~0,2%
set day=%SvnFileDate:~3,2%
set hours=%SvnFileDate:~11,2%
set minutes=%SvnFileDate:~14,2%
set datetime=%year%%month%%day%%hours%%minutes%
:: Folder for Functions
set func=%~dp0%Functions\*.sql
setlocal enableextensions enabledelayedexpansion
@for %%i in (%func%) do set FuncFileDate=%%~ti& ^
set year2=!FuncFileDate:~8,2!& ^
set month2=!FuncFileDate:~0,2!& ^
set day2=!FuncFileDate:~3,2!& ^
set hours2=!FuncFileDate:~11,2!& ^
set minutes2=!FuncFileDate:~14,2!& ^
set datetime2=!year2!!month2!!day2!!hours2!!minutes2!& ^
if "!datetime!" LSS "!datetime2!" type "%%i" >> InstallScript.sql
:: I would add similiar code for each folder, one for Views, Stored Procs, etc...
endlocal
pause