Script for renaming files using numbers: Difference between revisions

From Wurst-Wasser.net
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
If you don't want to use [[Better Finder Rename]] and still want to rename all taken pictures<ref>you took with [[Raspberry Pi Camera Setup for Time-Lapse|this]]</ref> you might find this handy:
If you don't want to use [[Better Finder Rename]] and still want to rename all taken pictures<ref>you took with [[Raspberry Pi Camera Setup for Time-Lapse|this]]</ref> 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}"
# (Un)Main
ls -1 "${1}" | sort -n | while read LFILENAME; do
      NEWFILENAME="`echo \"${LFILENAME}\" | sed s/-//\g | sed s/_//\g`"
      echo "NEWFILENAME: ${NEWFILENAME}"
      mv "${GFOLDERIN}"/"${LFILENAME}" "${GFOLDERIN}"/"${NEWFILENAME}"
done


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


----
----

Revision as of 23:19, 30 March 2014

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}"

# (Un)Main
ls -1 "${1}" | sort -n | while read LFILENAME; do
     NEWFILENAME="`echo \"${LFILENAME}\" | sed s/-//\g | sed s/_//\g`"
     echo "NEWFILENAME: ${NEWFILENAME}"
     mv "${GFOLDERIN}"/"${LFILENAME}" "${GFOLDERIN}"/"${NEWFILENAME}"
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".


  • Footnotes:
  1. you took with this