简体   繁体   中英

Batch - Forfiles in loop with multiple file types

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?

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
  )
)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM