2

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?

2 Answers 2

3

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
  )
)
Sign up to request clarification or add additional context in comments.

5 Comments

I'm having problems getting the editor to accept my code. I keep getting an error when I try to post a certain line. I'm trying to figure out the problem...bear with me.
Weird...I had to put the codeblock inside a block quote, otherwise the quotes around "cmd /c echo @relpath" were causing a problem and I'd get an error when I tried to post or update the answer.
Well, it almost works, got me further than before :D however, for some reason it finds only the types of the first one (.tga in this case, but when i change order it is .png) and for the other one it writes ERROR: Files of type "*.png" not found.
When I said it works for me, I meant with the ECHO %%A. Looking at your code, towards the end you have CD !Convertfolder!. That could be your problem. You are CDing into another folder and then when the next forfiles command runs, it's running in another folder that doesn't contain any of the files of the type it's looking for.
Oh yes! That is exactly the problem! Thanks a lot!
0

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.

1 Comment

Well, I tried various combination of quotation marks before posting here, that wasn't an issue :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.