You pass the absolute path to the loop FOR. But even with a relative path, the loop FORdoes too much and converts it to an absolute path.
The trick here is to replace the absolute path in the loop FOR.
Create a copy of the loop variable in the real variable
set AA=%%a
Then replace the prefix + backslash with nothing in the "array" list
set list[!i!]=!AA:%folders%\=!
full fixed code:
@echo off
setlocal EnableDelayedExpansion
SET folders=C:\Main
rem Populate the array with existent files in folder
set i=0
for /r "%folders%" /d %%a in (*) do (
set /A i+=1
rem create a copy of the loop variable in a real variable
set AA=%%a
rem replace prefix+backslash by nothing in a the list "array"
set list[!i!]=!AA:%folders%\=!
)
set foldnum=%i%
rem Display array elements
for /L %%i in (1,1,%foldnum%) do (SET array[%%i]=!list[%%i]!)
for /F "tokens=2 delims==" %%f in ('set array[') do echo %%f
%folders% .