Reputation: 73
I am trying to make a batch file for converting certain file types. So I don't put more useless loops in the code, I wanted to put it into one loop.
This is my code so far:
cd "%inputdir%"
setlocal disableDelayedExpansion
for /f "delims=" %%A in ('forfiles /s /m *.tga /c "cmd /c echo @relpath"') do (
set "file=%%~A"
setlocal enableDelayedExpansion
set filenametmp=%outputdir%!file:~1,-4!.paa
setlocal enableDelayedExpansion
For %%A in ("!filenametmp!") do (
Set foldertmp=%%~dpA
)
setlocal enableDelayedExpansion
IF NOT EXIST "!foldertmp!" (
mkdir "!foldertmp!"
)
endlocal
cd !Convertfolder!
Pal2PacE %inputdir%!file:~1! !filenametmp!
)
I used this answer to improve the for loop into:
for /f "delims=" %%A in ('for %%G in (.tga, .png) do 'forfiles /s /m *%%G /c "cmd /c echo @relpath"'') do (...
Unfortunately, it throws this error:
System cannot find file for %G in...
Does anyone know how to solve this?
Upvotes: 2
Views: 7619
Reputation: 20199
If I'm understanding correctly, I think this code will do what you want.
for %%G in (.tga, .png) do (
for /f "delims=" %%A in ('forfiles /s /m *%%G /c "cmd /c echo @relpath"') do (
REM The ECHO below is just for testing.
REM Put the code from inside your FOR loop here.
ECHO %%A
)
)
Upvotes: 3
Reputation: 80033
I believe, but have not tested:
for /f "delims=" %%A in ('for %%G in (.tga, .png) do forfiles /s /m *%%G /c "cmd /c echo @relpath"') do (...
should work, and the quotes around the forfiles
command are confusing the issue.
Upvotes: 0