I’m messing around in DOS Batch and writing code that loops through files in a directory and adds the last four characters of the file name to an array. The problem is that there are duplicates in my array. Is there a way to only add the value to an array if it doesn’t exist yet?
@echo off
setlocal enableDelayedExpansion
set i=0
for %%f in (*00.DIF) do (
set fname=%%~nf
set year=!fname:~-4!
::echo !year!
set Obj[!i!].name=!year!
set /a i=!i!+1
)
set lastindex=!i!
for /L %%f in (0,1,!lastindex!) do (
echo !Obj[%%f].name!
)