FOR %%A IN (*.*) DO (
echo %%A
set myfilename=%%A
echo %%myfilename
)
The "set myfilename=%%A" does not work for each instance of the for loop, just one time .. so, the echo will only output the first filename and I don't understand why?
Thanks in advance!
Why does this not work?
Moderator: DosItHelp
Re: Why does this not work?
Environmental variables are expanded by putting percent symbols on each side of the variable name. But since you are inside a parenthesised code block you need to use delayed expansion for the variables to output correctly. This is done by using exclamation points.
@echo off
Setlocal enabledelayedexpansion
FOR %%A IN (*.*) DO (
echo %%A
set myfilename=%%A
echo !myfilename!
)
@echo off
Setlocal enabledelayedexpansion
FOR %%A IN (*.*) DO (
echo %%A
set myfilename=%%A
echo !myfilename!
)