Page 1 of 1

Using for to search a folder and all its subfolders

Posted: 03 Apr 2010 12:17
by Pyromaniac
is this possible? I have created a batch file that searches for all .vtf files without an according .vmt file. And creates a vmt for them.
It works perfectly other than you have to specify the subfolder where the certain textures are located. I want it to scan anything within the materials folder, and all its subfolders. This is required because many of the subfolders names change and new ones get added/removed. Sorry if im vague or confusing im in a hurry.

Heres the code i have now:

Code: Select all

@echo off
:Menu
echo Batch file created by Pyromaniac1444, type the directory below...
set /p diry=Directory: C:\Steam\steamapps\pyromaniac1444\half-life 2\hl2\materials\
echo Finding all materials in %diry%...
for %%M in ("C:\Steam\steamapps\pyromaniac1444\half-life 2\hl2\materials\%diry%\*.vtf") do (
echo Scanning %%~nM...
if not exist %%~pM%%~nM.vmt (
echo "VertexLitGeneric" > %%~pM%%~nM.vmt
echo { >> %%~pM%%~nM.vmt
echo     "$basetexture" "%diry%\%%~nM.vtf" >> %%~pM%%~nM.vmt
echo } >> %%~pM%%~nM.vmt
echo Missing vmt for file %%~nM, file %%~nM.vmt created.
)
)
echo -------------------------
echo File creation is complete!
echo -------------------------
pause
goto Menu


I appreciate any help, im quite the batch noob. :c

Re: Using for to search a folder and all its subfolders

Posted: 03 Apr 2010 14:00
by Pyromaniac
I got dir to search subfolders with /s and get a nice list with /b.

I make dir export the list to a file called list.tmp, Im attempting to make FOR check each of the files in the list, but all it does is check the file list.tmp, how do i make it use the variables inside the list?

Re: Using for to search a folder and all its subfolders

Posted: 05 Apr 2010 10:00
by avery_larry
for /f

instead of just

for