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 1 Answer
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:
In a batch file you need to replace
%with%%(in a batch file use %%a, in acmdshell use%a)There is a possibility some files may get processed twice, so you should use
for /ftogether withdir).
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 /Fand not the simpleFOR.The
FOR /Fgathers the entire result of theDIRcommand before it begins iterating, whereas the simpleFORbegins 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
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- dir - Display a list of files and subfolders.
- for /f - Loop command against the results of another command.