home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
pcmagazi
/
1992
/
04
/
iter.bat
< prev
next >
Wrap
DOS Batch File
|
1991-06-12
|
4KB
|
131 lines
@ECHO OFF
IF '%1'=='' GOTO EntryErr
IF %1==cleanup GOTO end
IF %1==CLEANUP GOTO end
IF '%2'=='' GOTO EntryErr
REM Create file using first parameter
IF EXIST %1\NUL GOTO fail
IF EXIST %1 GOTO fail
MD %1
REM > %1\%1
REM Determine inidividual digits and length of first parameter
FOR %%a IN (0 1 2 3 4 5 6 7 8 9) DO IF EXIST %1\%%a* SET _1=%%a
SET digcount=1
IF EXIST %1\%_1% GOTO found
IF '%_1%'=='' GOTO EntryErr
FOR %%a IN (0 1 2 3 4 5 6 7 8 9) DO IF EXIST %1\?%%a* SET _2=%%a
SET digcount=2
IF EXIST %1\%_1%%_2% GOTO found
IF '%_2%'=='' GOTO EntryErr
FOR %%a IN (0 1 2 3 4 5 6 7 8 9) DO IF EXIST %1\??%%a* SET _3=%%a
SET digcount=3
IF EXIST %1\%_1%%_2%%_3% GOTO found
IF '%_3%'=='' GOTO EntryErr
FOR %%a IN (0 1 2 3 4 5 6 7 8 9) DO IF EXIST %1\???%%a* SET _4=%%a
SET digcount=4
IF EXIST %1\%_1%%_2%%_3%%_4% GOTO found
IF '%_4%'=='' GOTO EntryErr
FOR %%a IN (0 1 2 3 4 5 6 7 8 9) DO IF EXIST %1\????%%a* SET _5=%%a
SET digcount=5
IF EXIST %1\%_1%%_2%%_3%%_4%%_5% GOTO found
IF '%_5%'=='' GOTO EntryErr
FOR %%a IN (0 1 2 3 4 5 6 7 8 9) DO IF EXIST %1\?????%%a* SET _6=%%a
SET digcount=6
IF EXIST %1\%_1%%_2%%_3%%_4%%_5%%_6% GOTO found
IF '%_6%'=='' GOTO EntryErr
FOR %%a IN (0 1 2 3 4 5 6 7 8 9) DO IF EXIST %1\??????%%a* SET _7=%%a
SET digcount=7
IF EXIST %1\%_1%%_2%%_3%%_4%%_5%%_6%%_7% GOTO found
IF '%_7%'=='' GOTO EntryErr
FOR %%a IN (0 1 2 3 4 5 6 7 8 9) DO IF EXIST %1\???????%%a* SET _8=%%a
SET digcount=8
IF EXIST %1\%_1%%_2%%_3%%_4%%_5%%_6%%_7%%_8% GOTO found
IF '%_8%'=='' GOTO EntryErr
REM Create and run temporary files
:found
DEL %1\%1
RD %1
ECHO IF NOT '%%iterdone%%'=='' GOTO end > iter_run.bat
ECHO IF %%1%%2%%3%%4%%5%%6%%7%%8==%1 GOTO quit >> iter_run.bat
SHIFT
SHIFT
ECHO CALL %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 >> iter_run.bat
ECHO GOTO end >> iter_run.bat
ECHO :quit >> iter_run.bat
ECHO ECHO %%1%%2%%3%%4%%5%%6%%7%%8 iterations completed. >> iter_run.bat
ECHO SET iterdone=1 >> iter_run.bat
ECHO :end >> iter_run.bat
ECHO Running %0 %_1%%_2%%_3%%_4%%_5%%_6%%_7%%_8% times.
SET args= |REM space character at end of set statement prevents error later.
SET iteri=1
SET iterj=2
SET iterdone=
:loop
IF %iteri%==%digcount% GOTO lastpass
ECHO FOR %%%%a IN (0 1 2 3 4 5 6 7 8 9) DO IF '%%iterdone%%'=='' CALL iter_%iterj% %args% %%%%a > iter_%iteri%.bat
SET args=%args% %%%iteri%
SET iteri=%iterj%
IF %iterj%==7 SET iterj=8
IF %iterj%==6 SET iterj=7
IF %iterj%==5 SET iterj=6
IF %iterj%==4 SET iterj=5
IF %iterj%==3 SET iterj=4
IF %iterj%==2 SET iterj=3
GOTO loop
:lastpass
SET iteri=
SET iterj=
ECHO FOR %%%%a IN (0 1 2 3 4 5 6 7 8 9) DO IF '%%iterdone%%'=='' CALL iter_run %args% %%%%a > iter_%digcount%.BAT
SET args=
CALL iter_1
GOTO end
REM Error code for improper entry by operator
:EntryErr
IF EXIST %1\%1 DEL %1\%1
IF EXIST %1\NUL RD %1
ECHO USAGE: ITER x command arg1 arg2 ... arg9
ECHO where x is a number of less than 9 digits representing the number
ECHO of iterations of the command to run.
GOTO end
REM Error code for first parameter can't be used to create directory
:fail
ECHO Unable to run -- %1 exists as a directory or file. Use a
ECHO different count or run in another directory.
REM Code to clear all variables used and delete temporary files
:end
ECHO Cleaning up...
SET _1=
SET _2=
SET _3=
SET _4=
SET _5=
SET _6=
SET _7=
SET _8=
SET args=
SET digcount=
SET iterdone=
SET iteri=
SET iterj=
IF EXIST Iter_*.BAT DEL ITER_*.BAT