renaming many gifs in folder

188 views Asked by At

I have a lot of files that have random generated names like notqr64SC51ruz6zso3_250.gif and I would like to rename them to simply 1.gif, 2.gif etc.

What would be the best way to accomplish this?

1

There are 1 answers

0
manlio On

A simple UNIX shell script:

N=1; for i in `ls *.gif` ; do mv $i $N.gif ; N=$((N+1)); done

If you need padding:

N=1
for i in *.gif; do
  printf -v new "%06d.gif" ${N}
  mv -- "$i" "$new"
  N=$((N+1));
done

Under Windows you can use a (similar) batch file:

Rename Multiple files with in Dos batch file


If you can use Python:

import glob
import os

files = glob.glob("/path/to/folder/*.gif")    

n = 0
for fn in files:
    os.rename(fn, str(n).zfill(6) + '.gif')
    n += 1