The reason the previous code did not work with filenames with spaces is that, by default, the FOR /F behaviour is to treat the lines processed (in this case, the lines of text output by DIR /a-d /b) as a series of space-delimited "tokens". That is, if it found the line
c:\my folder\whatever path\something.txt
It would treat the lines as having 3 tokens and %%A would only contain the first token
c:\my
because FOR /F would stop at the first space.
This behaviour can be modified with a suitable "delims=" section. I won't go into what "tokens=" does, except to say that you can use it to chop up the line into tokens and isolate them.
The modifier "delims==" instructs FOR /F to consider the delimiters to be the line start and finish, thus preserving the whole line.
The problem would have become visible earlier if the path to the source folder had spaces, since these would have cause the batch to not function at all