2

So I am trying to a procedure of converting images in a directory, but it just doesn't run at all, and I fail to see what's incorrect in my batch code:

FOR /R %a in (*.png) DO (
    files\pngnq -s 1 -n 16 %~fa 
    ren *nq8.png "%~na.png"
    files\gimconv "%~na.png" --format_style psp --format_endian little --pixel_order faster --image_format index4
    del "%~na.png"
    )

the error it outputs is in french "in was not expected" (in était inattendu).

EDIT: this is the orginal (working code) code:

set file=*.png
files\pngnq -s 1 -n 16 %file% 
ren *nq8.png 12345.png
files\gimconv 12345.png --format_style psp --format_endian little --pixel_order faster --image_format index4
del 12345.png
ren *.gim READY4BIT.gim
DavidPostill
  • 162,382
Omarrrio
  • 227

1 Answers1

2

I fail to see what's incorrect in my batch code:

FOR /R %a in (*.png) DO (
    files\pngnq -s 1 -n 16 %~fa 
    ren *nq8.png "%~na.png"
    files\gimconv "%~na.png" --format_style psp --format_endian little --pixel_order faster --image_format index4
    del "%~na.png"
    )

I can see two obvious issues with the above code:

  1. In a batch file you need to replace % with %% (in a batch file use %%a, in a cmd shell use %a)

  2. There is a possibility some files may get processed twice, so you should use for /f together with dir).

There may be other things wrong as well, but I don't have the required programs to test it.

Use the following batch file instead:

for /f "tokens=*" %%a in ('dir /b *.png') do (
    files\pngnq -s 1 -n 16 %%~fa 
    ren *nq8.png "%%~na.png"
    files\gimconv "%%~na.png" --format_style psp --format_endian little --pixel_order faster --image_format index4
    del "%%~na.png"
    )

Note:

It is critical that you use FOR /F and not the simple FOR.

The FOR /F gathers the entire result of the DIR command before it begins iterating, whereas the simple FOR begins iterating after the internal buffer is full, which adds a risk of renaming the same file multiple times.

as advised by dbenham in his answer to add "text" to end of multiple filenames:


Further Reading

DavidPostill
  • 162,382