I understand the magic of the setlocal enabledelayedexpansion; this brought me one step further but I am still not completely happy. I am now able to assign the filename to a !loop variable!, but I fail to use that variable subseqently. I try to get the filename without the extension. There must be something else that I am unaware of.
This is my coding now:
::process all files in directory
setlocal enabledelayedexpansion
for %%f in (C:\windows\*.ico) do (
echo F=%%f
set myname=%%f
echo.N=!myname!
call :strlen myLen "!myname!"
echo.myLen=!myLen!
set /A L=myLen-3 + 1
set str=!myname!
echo.str1=!str! L=!L!
set str=!str:~0,!L! ! <-Remove extension from filename
echo.str2=!str! <-This does not work!
)
Here is the output of my call :
F=C:\windows\AnyWeb Print.ico
N=C:\windows\AnyWeb Print.ico
Strlen C:\windows\AnyWeb Print.ico
myLen=25
str1=C:\windows\AnyWeb Print.ico L=23
str2=L <--- what went wrong ????
~-modifiers of theformeta-variable, like%%~Nfto get the base name and%%~Xfto get the extension, for instance? N. B.: The Windows command prompt is NOT a DOS prompt!