0

Greetings and Salutations All,

I'm trying to create an animation using imagemagick via:

convert -delay 80 -loop 0 *.png ani.gif

The logic is finding all the .png files, except the file names are not listed numerically. This causes the animation sequence to be poorly built.

e.g

-a---         3/17/2015   8:36 PM      14147 26.png
-a---         3/17/2015   8:37 PM      13904 260.png
-a---         3/17/2015   8:37 PM      13981 261.png
-a---         3/17/2015   8:37 PM      13863 262.png
-a---         3/17/2015   8:37 PM      14026 263.png
-a---         3/17/2015   8:37 PM      14023 264.png
-a---         3/17/2015   8:37 PM      14038 265.png
-a---         3/17/2015   8:37 PM      13913 266.png
-a---         3/17/2015   8:37 PM      14003 267.png
-a---         3/17/2015   8:37 PM      14000 268.png
-a---         3/17/2015   8:37 PM      13887 269.png
-a---         3/17/2015   8:36 PM      14025 27.png

I've tried to force the directory to a list by time & date to no avail via:

set dircmd=/o:d

How could I get it so that the files would be internally listed as:

-a---         3/17/2015   8:36 PM      14147 26.png
-a---         3/17/2015   8:36 PM      14025 27.png
-a---         3/17/2015   8:37 PM      13904 260.png
-a---         3/17/2015   8:37 PM      13981 261.png
-a---         3/17/2015   8:37 PM      13863 262.png
-a---         3/17/2015   8:37 PM      14026 263.png
-a---         3/17/2015   8:37 PM      14023 264.png
-a---         3/17/2015   8:37 PM      14038 265.png
-a---         3/17/2015   8:37 PM      13913 266.png
-a---         3/17/2015   8:37 PM      14003 267.png
-a---         3/17/2015   8:37 PM      14000 268.png
-a---         3/17/2015   8:37 PM      13887 269.png

Then when the convert command is run the right sequence would be pressed into a gif?

1 Answer 1

1

Presumably your convert program sorts the files alphabetically by name when you use a wildcard. The simplest solution would be to rename the files with zero padding so that the file names sort in the proper numeric order.

I've written a hybrid JScript/batch utility called JREN.BAT that can use regular expression replacement to rename files. It is pure script that runs natively on any Windows machine from XP onward.

JREN.BAT makes the solution extremely simple (assuming, for example, you don't already have an existing 027.png that conflicts with 27.png):

jren "^\d+(?=\.png)" "lpad($0,'000')" /j

After running the command, a file named 5.png would become 005.png, and 27.png would become 027.png. Your original convert command should then be able to process the files in the correct order.

Use jren /? to get full documentation on the many options available to JREN.BAT


You can do the rename using pure batch, but it is not nearly as convenient

@echo off
setlocal enableDelayedExpansion
for /f "delims=" %%F in (
  'dir /b /a-d ???.png ^| findstr "^[0-9][0-9]*\.png$" /i'
) do (
  set "num=000%%~nF"
  ren "%%F" "!num:~-3!%%~xF"
)
1
  • or using PowerShell: dir *.png | foreach {Move $_.Name $_.Name.PadLeft(10,'0')} Commented Mar 18, 2015 at 17:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .