Page 1 of 1

Setting variables in a for line?

Posted: 04 Apr 2010 09:20
by Pyromaniac
I have a script im creating that searches your steam folder for missing texture files and creates them as they are found. So far its pretty much done, but I can't figure out why I can't set the variable "list" in the for loop. It comes up as undefined, but when i place it outside of the for loop, it sets fine. Is there an explanation for this? Any help is appreciated.

Heres the batch im making

Code: Select all

@echo off
SetLocal EnableDelayedExpansion
echo ---------------------------------------------------------
echo                Pyromaniac's vmt creator!
echo ---------------------------------------------------------
set filefound=                 No files were missing!
set usrdir=C:\Steam\steamapps\pyromaniac1444\half-life 2\hl2\materials\
call :getlength "%usrdir%" length
cd C:\Steam\steamapps\pyromaniac1444\half-life 2\hl2\materials\
echo Searching...
for /f "tokens=*" %%A in ('dir *.vtf /s /b') do (
set list=%%~fA
echo Scanning %%~nA...
if not exist %%~pnA.vmt (
set filefound=         Missing vmt's were found and generated.
echo "VertexLitGeneric" > %%~pnA.vmt
echo { >> %%~pnA.vmt
set list=%list:~-%length%%
echo     "$basetexture" "%list%" >> %%~pnA.vmt
echo } >> %%~pnA.vmt
echo Missing vmt for file %%~nA.
)
)
echo ---------------------------------------------------------
echo                File creation is complete!
echo %filefound%
echo ---------------------------------------------------------

:getlength
SetLocal
set len=0
set str=%~1
if not defined str goto :eof
set str=%str:"=.%987654321
:loop
if not "%str:~18%"=="" set str=%str:~9%& set /a len+=9& goto loop
set num=%Str:~9,1%
set /a len=len+num
EndLocal&set %2=%len%&goto :eof

Re: Setting variables in a for line?

Posted: 05 Apr 2010 10:05
by avery_larry
set list=!list:~-%length%!
echo "$basetexture" "!list!" >> %%~pnA.vmt

or don't bother with the first set:

echo "$basetexture" "!list:~-%length%!" >> %%~pnA.vmt