|
Answer» Hi All
I have set of bat files. Following highlighted text are common to all bat files.
SQLCMD -S ADC012-PC1\SQLExpress -d test -i E:\REPORTS\SQLtemplates\R0001.sql -o E:\Reports\Output\R0001.csv -s","
All bat files are stored in a E:\Reports\BatFiles folder. I want to do following things USING a new bat file.
1. Create new folder in E:\Reports. new folder name is 2011. And also two folders which are called BatFiles and Output folders should be created WITHIN the 2011 folder. (i.e E:\Reports\2011\BatFiles and E:\Reports\2011\Output
2. Copy all bat files which are stored in E:\Reports\BatFiles folder to E:\Reports\2011\BatFiles folder
3. Then replace "E:\Reports\Output\ " text into "E:\Reports\2011\Output\" in EVERY bat file content.
Please advice me how to achieve my requirements.
Thank You
Based on the information you have given, this should hopefully work:
@echo off setlocal enabledelayedexpansion if not exist E:\Reports\2011 md E:\Reports\2011 if not exist E:\Reports\2011\BatFiles md E:\Reports\2011\BatFiles if not exist E:\Reports\2011\Output md E:\Reports\2011\Output cd /d "E:\Reports\BatFiles" for %%A in (*.bat) do ( echo Processing file: %%~dpnxA if exist "E:\Reports\2011\BatFiles\%%~nxA" del "E:\Reports\2011\BatFiles\%%~nxA" for /f "delims==" %%B in ('type %%A') do ( set iline=%%B if "!iline:~0,79!"=="sqlcmd -S ADC012-PC1\SQLExpress -d test -i E:\Reports\SQLtemplates\R0001.sql -o" ( set oline=!iline:E:\Reports\Output\=E:\Reports\2011\Output\! echo !oline!>>"E:\Reports\2011\BatFiles\%%~nxA" ) else ( echo !iline!>>"E:\Reports\2011\BatFiles\%%~nxA" ) ) ) echo Done echo. pause
|