Clearing an array is done as a partial match? Why?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 544
Joined: 07 Jan 2016 07:47

Clearing an array is done as a partial match? Why?

#1 Post by SIMMS7400 » 21 Jul 2023 02:39

HI All -

I have the following Array/List setup. The first position in the list is a filename mask. What's interesting is if I have 2 like file names but still unique, when I clear the array before each iteration, the other like array definition is cleared too.

For instance, when running the below code only 1 array/list definition is registered. However, if I switch "PRODUCT_PARENT" to "PARENT_PRODUCT", it works fine. Why does the array clear seem to do a partial match when clearing?

Code: Select all

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

FOR %%a IN (
	"PRODUCT_PARENT|DLR_PROD_PARENT_LOAD|inbox/Metadata|REPLACE|STORE_DATA|||"
	"PRODUCT|DLR_IMP_PROD|inbox/Metadata|REPLACE|STORE_DATA|||"
) DO SET "GROUP=%%~a" & CALL :DEFINE_LISTS "DM" "MD"

REM Display Arrays
SET STR[
pause


:DEFINE_LISTS

IF /I "[%~2]"=="[D]"  SET "TYPE=Data"
IF /I "[%~2]"=="[MD]" SET "TYPE=Metadata"
	
SET "GROUP=!GROUP:||=|null|!"
FOR %%v IN ("!GROUP:||=|null|!") DO FOR /F "tokens=1-13 delims=|" %%A IN ("%%~v") DO (

	REM Clear Array
	FOR /F "delims==" %%1 IN ('SET STR[%%A') DO SET "%%1="
	
	IF NOT "[%%B]"=="[null]" SET "STR[%%A].DLR=%%B"
	IF NOT "[%%C]"=="[null]" SET "STR[%%A].LOC=%%C"
	IF NOT "[%%D]"=="[null]" SET "STR[%%A].IMP=%%D"
	IF NOT "[%%E]"=="[null]" SET "STR[%%A].EXP=%%E"
	IF NOT "[%%F]"=="[null]" SET "STR[%%A].RMT_LOGIN=%%F"
	IF NOT "[%%G]"=="[null]" SET "STR[%%A].DEL=%%G"
	IF NOT "[%%H]"=="[null]" SET "STR[%%A].TLOC=%%H"
	IF NOT "[%%J]"=="[null]" SET "STR[%%A].INTRA=%%J"
	IF NOT "[%%K]"=="[]" IF NOT "[%%K]"=="[null]" (
		SET "STR[%%A].CCNTS=%%K"
		SET "CCNTS=%%K"
	)
	IF NOT "[%%L]"=="[]" IF NOT "[%%L]"=="[null]" SET "STR[%%A].CCNTD=%%L"
	IF NOT "[%%M]"=="[]" IF NOT "[%%M]"=="[null]" SET "STR[%%A].DLOCD=%%M"
	SET "STR[%%A].TYPE=!TYPE!"
	
)
CLS
GOTO :EOF

OJBakker
Expert
Posts: 89
Joined: 12 Aug 2011 13:57

Re: Clearing an array is done as a partial match? Why?

#2 Post by OJBakker » 21 Jul 2023 03:22

Set Var reports all variables starting with Var
Try add a closing "]" in the clear routine.

Code: Select all

REM Clear Array
	FOR /F "delims==" %%1 IN ('SET STR[%%A]') DO SET "%%1="

Post Reply