I am trying to iterate over a set of numbers of 4 sig figs, padded with zeros if number is small like 1 = 0001, I echo !filenum:~-4! which gives me the expected results of 0001, 0002, etc. But when I try to set a variable to !filenum:~-4! it does not work
@echo off
setlocal EnableDelayedExpansion
for /L %%i in (1, 1, 10) do (
echo %%i
set filenum=0000%%i
echo filenum !filenum!
echo !filenum:~-4!
set f = !filenum:~-4!
IF "!f!"=="" ECHO MyVar is NOT defined
)