Here is another method that show you how to populate array dynamically using a counter.
You can for example populate two arrays with names and full paths dynamically while we increment the counter into a loop forindo
@echo off
Title Print the values in an array using batch
Set "MasterFolder=C:\FRST"
Set "RecentFolder="
set /a "count=0"
Setlocal EnableDelayedExpansion
Rem Populate two arrays with names and full paths dynamically while we increment the counter
@FOR /F "delims=" %%a IN ('dir "%MasterFolder%" /b /ad-h /t:c /o-d') DO (
if not defined RecentFolder (
set /a "Count+=1"
set "RecentFolderName[!Count!]=%%~na"
set "RecentFolderPath[!count!]=%%~fa"
)
)
Rem Display numbered Folders Names and full paths
color 0A & Mode 90,30 & cls & echo(
@for /L %%i in (1,1,%Count%) do (
set "RecentName=[%%i] - !RecentFolderName[%%i]!"
set "RecentFullPath=FullPath - "!RecentFolderPath[%%i]!""
echo !RecentName!
echo !RecentFullPath!
echo --------------------------------------------------
)
Pause