Using for to search a folder and all its subfolders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Pyromaniac
Posts: 3
Joined: 03 Apr 2010 12:11

Using for to search a folder and all its subfolders

#1 Post by Pyromaniac » 03 Apr 2010 12:17

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

Pyromaniac
Posts: 3
Joined: 03 Apr 2010 12:11

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

#2 Post by Pyromaniac » 03 Apr 2010 14:00

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?

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

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

#3 Post by avery_larry » 05 Apr 2010 10:00

for /f

instead of just

for

Post Reply