home
Dos batch file concatenate files loop subdirectories find strings
Author Nigel Rivett
For the following create a file with extension .bat, copy the code into the file and run it.
Concatenate all .sql files in a folder
type *.sql > concat.txt
Concatenate all .sql files returned from a dir command
echo. > concat.txt
for /f "delims=" %%a in ('dir /B *.sql') do type %%a >> concat.txt
Concatenate all .sql files returned from a dir command using a subroutine
echo. > concat.txt
for /f "delims=" %%a in ('dir /B *.sql') do call :subr "%%a"
goto:EOF
:subr
type %1 >> concat.txt
goto:EOF
Concatenate all .sql files include the file path and name
echo. > concat.txt
for /f "delims=" %%a in ('dir /B *.sql') do call :subr "%%a"
goto:EOF
:subr
echo. >> concat.txt
echo %1 >> concat.txt
echo. >> concat.txt
type %1 >> concat.txt
goto:EOF
Concatenate all .sql files in all subdirectories include the file path and name
echo. > concat.txt
for /f "delims=" %%a in ('dir /B /s *.sql') do call :subr "%%a"
goto:EOF
:subr
echo. >> concat.txt
echo %1 >> concat.txt
echo. >> concat.txt
type %1 >> concat.txt
goto:EOF
Create text file of all .sql filenames in all subdirectories that include a find string
echo. > concat.txt
for /f "delims=" %%a in ('dir /B /s *.sql') do call :subr "%%a"
goto:EOF
:subr
findstr "myfindstring" %1
if %ERRORLEVEL% NEQ 1 type %1 >> concat.txt
goto:EOF
home