How to arrange and array/list?
Posted: 02 Jan 2022 17:54
Hi Folks -
I have the following array (well, I believe it's technically called a "list):
What happens is that there is a directory with all oft he above files so I read them into a for loop. But what I need do is arrange the file names in a comma delimited list from highest to lowest. You'll see the 4th position of the array/list definition dictates the order. I'm sure there is an easy way to do this but can't figure it out. Thanks!
I have the following array (well, I believe it's technically called a "list):
Code: Select all
@echo off
setlocal EnableDelayedExpansion
FOR %%A IN (
"CITY.txt|CITY_JOB|CITY_Errors.zip|"
"COUNTY.txt|COUNTY_JOB|COUNTY_Errors.zip|2"
"REGION.txt|REGION_JOB|REGION_Errors.zip|1"
) DO SET "GROUP=%%~A" & CALL :DEFINE_ARRAY
:: Order file list from greatest to least
:: end result should be comma delimited variable as such = COUNTY.txt,REGION.txt,CITY.txt
pause
:DEFINE_ARRAY
FOR %%v IN ("!GROUP:||=|null|!") DO FOR /F "tokens=1-4 delims=|" %%A IN ("%%~v") DO (
IF NOT "[%%B]"=="[null]" SET "STR[%%A].OLU_JOB=%%B"
IF NOT "[%%C]"=="[null]" SET "STR[%%A].OLU_ERR=%%C"
IF NOT "[%%D]"=="[null]" SET "STR[%%A].OLU_TYPE=%%D"
)
GOTO :EOF