Fumbling a Nested Batch File
Posted: 15 Feb 2018 04:46
My batch file generates a directory, files and a batch file which generates a batch file. Download SetupNestBat.Bat and run it as a demo.
I have a few issues:
SetupNestBat.Bat
Proper NestBat.bat run as: Nestbat >Batling.bat
Run Batling.bat as: Batling >Batling.log
I have a few issues:
- SetupNestBat.Bat does not write the '%%', '%1' or '%2'
- Using filename without the extension (ie I want Best1.dta not Best1.dat.dta)
- Inserting a '>' in batch file comment lines without redirecting the line (eg for Usage line)
- Appending a '> nul' in the output rather than a second redirection on the line (eg after redirected copy lines
- Echoing lines to con while output directed to file (eg done.)
SetupNestBat.Bat
Code: Select all
:: Create NestBat.bat and demo files
::
:: Ver 15/02/2018 (CC BY-SA 4.0)
::
mkdir NestBat
cd NestBat
echo @echo off > NestBat.bat
echo ::
echo :: Usage: NestBat [File (without extension) [File (without extension)]] > Batling.bat >> NestBat.bat
echo :: >> NestBat.bat
echo :: Ver 15/02/2018 (CC BY-SA 4.0) >> NestBat.bat
echo :: >> NestBat.bat
echo echo Generating ... >> NestBat.bat
echo :: >> NestBat.bat
echo For %%f in (%1*.dat) do ( >> NestBat.bat
echo echo ::>> NestBat.bat
echo echo ::*** %%f >> NestBat.bat
echo echo copy %%f DAT >> NestBat.bat
echo echo copy %%f.dta DTA >> NestBat.bat
echo echo copy %%f.dtt DTT >> NestBat.bat
echo :: >> NestBat.bat
echo For %%g in (%2*.per) do ( >> NestBat.bat
echo echo ::** %%g >> NestBat.bat
echo echo copy %%g.per PER >> NestBat.bat
echo echo Program >> NestBat.bat
echo echo copy OUT %%f%%g.out >> NestBat.bat
echo echo :: >> NestBat.bat
echo ) >> NestBat.bat
echo echo :: >> NestBat.bat
echo ) >> NestBat.bat
echo echo done. >> NestBat.bat
echo :End >> NestBat.bat
:: Test Files
echo > Best1.dat
echo > Best1.dta
echo > Best1.dtt
echo > Test2.dat
echo > Test2.dta
echo > Test2.dtt
echo > Test3.dat
echo > Test3.dta
echo > Test3.dtt
echo > High.per
echo > Low.per
echo > OUT
cd ..
Code: Select all
@echo off
@echo off
:: Usage: NestBat [File (without extension) [File (without extension)]] > Batling.bat
::
:: Ver 15/02/2018 (CC BY-SA 4.0)
::
echo Generating ...
::
For %%f in (%1*.dat) do (
echo ::
echo ::*** %%f
echo copy %%f DAT
echo copy %%f.dta DTA
echo copy %%f.dtt DTT
echo ::
::
For %%g in (%2*.per) do (
echo ::** %%g
echo copy %%g.per PER
echo Program
echo copy OUT %%f%%g.out
echo ::
)
echo ::
)
echo done.
:End