simply spoken the task I want to accomplish is: Process something in accordance to unknown amount of parameters passed to a subroutine and their value, without the need of hundred IFs
Code: Select all
:subroutine
if "%1"=="foo1" do process something
...
if "%n"=="fooN" do process something
goto :eof
My actual intention is to have a subroutine that deletes in given string which is located in a text file and therein in the one and only line which contains drives, eg. C:\ D:\ ... Z:\ the drives passed, eg E:\ ... Z:\
Code snippet:
Code: Select all
SETLOCAL ENABLEDELAYEDEXPANSION
...
SET tmp_file=%TEMP%\FoundDrives.txt
fsutil fsinfo drives > %tmp_file%
FOR /l %%x IN (1,1,28) DO (
SET param_index=%%x
IF NOT "%!param_index!"=="" (
SET search=%!param_index!
FOR /f "tokens=*" %%y IN (%tmp_file%) DO (
SET drives=%%y
SET drives=!drives:%search%=%replace%!
ECHO !drives! > %tmp_file%
)
)
)
...
DEL %tmp_file% > NUL 2>&1
...
ENDLOCAL
GOTO :EOF
The problem I have is I don't know to correctly code the 3 lines
Code: Select all
SET param_index=%%x
IF NOT "%!param_index!"=="" (
SET search=%!param_index!
Any hints welcome.