Making image files into an ordered number sequence.

Say you have a bunch of files in a directory that need sensible filenames so that they can be fed into another program easily.

ie you want this.

0001.jpg
0002.jpg
0003.jpg
0004.jpg

from say this:

IMG_9998.JPG
IMG_9999.JPG
IMG_0001.JPG
IMG_0002.JPG

eg you camera has rolled over from IMG_9999.JPG  to IMG_0001.JPG

(actually this is a bad example). 
we need to tell find or ls below to order the files by creation date in this case.

just say you files looked like this.

IMG_3454.JPG
IMG_3455.JPG
IMG_3456.JPG
IMG_3457.JPG


(install gawk first)

find . -name '*.JPG' | gawk 'BEGIN{ a=1 }{ printf "mv \"%s\" %04d.jpg\n", $0, a++ }' | bash

Careful..  find will work recursively ls may work better...

ls *.JPG | gawk 'BEGIN{ a=1 }{ printf "mv \"%s\" %04d.jpg\n", $0, a++ }' | bash

work in progress....
Comments