This is the script:
:BEGIN
REM Creating CreateStatements Files...
@echo off
rem This script makes a CreateStatementsFiles.
rem Version: 3
rem Last script update on: 2012-08-30 by Joshua Moesa
:SET_ENVIRONMENT_VARIABLES
rem Setting environment variables
set rootPathBatchFile=C:\DBSCRIPTS\
set scriptRootPath=%rootPathBatchFile%scripts\
set fileOutput=%rootPathBatchFile%output.txt
set fileOutputSub=%rootPathBatchFile%outputSubRoutine.txt
:INIT
rem Cleaning-up
rem This script makes a CreateStatementsFiles.
rem Version: 3
rem Last script update on: 2012-08-30 by Joshua Moesa
:SET_ENVIRONMENT_VARIABLES
rem Setting environment variables
set rootPathBatchFile=C:\DBSCRIPTS\
set scriptRootPath=%rootPathBatchFile%scripts\
set fileOutput=%rootPathBatchFile%output.txt
set fileOutputSub=%rootPathBatchFile%outputSubRoutine.txt
:INIT
rem Cleaning-up
::Cleanup all mk_-files
FOR /R %rootPathBatchFile% %%G IN (mk_*.sql) DO (
DEL %%G
)
:CREATE_BUFFER
rem Printing all SQL filenames to buffer file
FOR /R %rootPathBatchFile% %%G IN (cr_*.sql) DO echo %%G >> %fileOutput%
::DEBUG
::echo %%~pG >> %fileOutput%
:PROCESS_BUFFER_FILE
FOR /R %rootPathBatchFile% %%G IN (mk_*.sql) DO (
DEL %%G
)
:CREATE_BUFFER
rem Printing all SQL filenames to buffer file
FOR /R %rootPathBatchFile% %%G IN (cr_*.sql) DO echo %%G >> %fileOutput%
::DEBUG
::echo %%~pG >> %fileOutput%
:PROCESS_BUFFER_FILE
rem Processing lines in the buffer file
FOR /F "tokens=*" %%A in (%fileOutput%) do (
call :process %%A
)
goto CLEANUP
:process
::echo %1
FOR /F "tokens=*" %%A in (%fileOutput%) do (
call :process %%A
)
goto CLEANUP
:process
::echo %1
set fullFileName=%1
call :parse "%fullFileName%"
goto :end
:parse
setlocal
set list=%1
set list=%list:"=%
goto :end
:parse
setlocal
set list=%1
set list=%list:"=%
FOR /f "tokens=4,5,6 delims=\" %%a IN ("%list%") DO (
if not "%%a" == "" call :sub %%a %%b %%c
if not "%%b" == "" call :parse "%%b %%b %%c"
)
endlocal
exit /b
:sub
if not "%%a" == "" call :sub %%a %%b %%c
if not "%%b" == "" call :parse "%%b %%b %%c"
)
endlocal
exit /b
:sub
setlocal
::DEBUG
::echo In subroutine
::echo %1 %2 %3 >> %fileOutputSub%
::echo %scriptRootPath%%1\%2\makefile.txt >> %fileOutputSub%
if not exist %scriptRootPath%%1\%2\mk_%2.sql (
echo prompt create %2 > %scriptRootPath%%1\%2\mk_%2.sql
)
echo @@%3 >> %scriptRootPath%%1\%2\mk_%2.sql
endlocal
exit /b
:CLEANUP
DEL %fileOutput%
:end
::DEBUG
::echo In subroutine
::echo %1 %2 %3 >> %fileOutputSub%
::echo %scriptRootPath%%1\%2\makefile.txt >> %fileOutputSub%
if not exist %scriptRootPath%%1\%2\mk_%2.sql (
echo prompt create %2 > %scriptRootPath%%1\%2\mk_%2.sql
)
echo @@%3 >> %scriptRootPath%%1\%2\mk_%2.sql
endlocal
exit /b
:CLEANUP
DEL %fileOutput%
:end
Some handy references I used:
- http://www.jamesewelch.com/2008/05/01/how-to-write-a-dos-batch-file-to-loop-through-files/
- http://stackoverflow.com/questions/1100452/get-filename-in-dos-for-loop
- http://weblogs.asp.net/jgalloway/archive/2006/11/20/top-10-dos-batch-tips-yes-dos-batch.aspx
- http://www.nickpisca.com/BLAST/index.php?title=Batch_Txt_Loop_with_Delimiter
- http://stackoverflow.com/questions/155932/how-do-you-loop-through-each-line-in-a-text-file-using-a-windows-batch-file
- http://stackoverflow.com/questions/2524928/dos-batch-iterate-through-a-delimited-string
0 reacties:
Post a Comment