I want to process all files in a directory, eg. replace the extension and rename the file. The problem is, I cannot move the filename into a variable (seems to be a problem with the scope of variables).
Here is what I have coded:
@echo off
cls
setlocal
set myname=hugo
echo myname=%myname%
::process all files in directory
for %%f in (C:\windows\*.ico) do (
echo F=%%f <--- this works fine
set myname=%%f <--- this does NOT work!
echo.myname=%myname%
)
echo myname=%myname% <--- displays last set
endlocal
And this is the output:
myname=hugo
F=C:\windows\AnyWeb Print.ico
myname=hugo
F=C:\windows\Dr. Printer Icon.ico
myname=hugo
F=C:\windows\SmartCMS2.ico
myname=hugo
myname=C:\windows\SmartCMS2.ico
I cannot modify the variable "myname" within he loop, but once the loop has ended, it contains the value, that I have tried to assign most recently.
Obviously I don't understand the way a batch file handles variables in a FOR loop. I seem to lack some info about it.