Script for renaming files using numbers

From Wurst-Wasser.net
Jump to navigation Jump to search

If you don't want to use Better Finder Rename and still want to rename all taken pictures[1] you might find this handy:

The Script

#!/bin/bash
#
# Author: Heiko Kretschmer
# Script: renameRaspiImagesWithNumbers.sh
# Purpose: Rename files, so ffmpeg can use it for creating a time-lapse-movie
#
#

# Globals
GFOLDERIN="${1}"
GCOUNTER=1

# (Un)Main
ls -1 "${1}" | sort -n | while read LFILENAME; do
     #NEWFILENAME="`echo \"${LFILENAME}\" | sed s/-//\g | sed s/_//\g`"
     NEWFILENAME="`printf %05d ${GCOUNTER}`.jpg"
     #echo "NEWFILENAME: ${NEWFILENAME}"
     mv "${GFOLDERIN}"/"${LFILENAME}" "${GFOLDERIN}"/"${NEWFILENAME}"
     let GCOUNTER=`expr ${GCOUNTER} + 1`
     #echo ${GCOUNTER}
done

What it does

  • It takes all images and removed the "-" and "_" from the filename, renaming f.e. 2014-03-30_10-30-46.jpg to 20140330103046.jpg, which makes it easy to digest for ffmpeg using -i "%14d.jpg"

It takes all images and removed the "-" and "_" from the filename, renaming f.e. 2014-03-30_10-30-46.jpg to 00001.jpg, which makes it easy to digest for ffmpeg using -i "%05d.jpg"


  • Footnotes:
  1. you took with this