-1

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
)

enter image description here

1 Answers1

0

I found the problem, the space after f when assigning the value change the name of the var to "f ". I got to remember that spaces matter in batch scripts