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
 
(4 intermediate revisions by the same user not shown)
Line 12: Line 12:
  # Globals
  # Globals
  GFOLDERIN="${1}"
  GFOLDERIN="${1}"
GCOUNTER=1
   
   
  # (Un)Main
  # (Un)Main
  ls -1 "${1}" | sort -n | while read LFILENAME; do
  ls -1 "${1}" | sort -n | while read LFILENAME; do
       NEWFILENAME="`echo \"${LFILENAME}\" | sed s/-//\g | sed s/_//\g`"
       #NEWFILENAME="`echo \"${LFILENAME}\" | sed s/-//\g | sed s/_//\g`"
       echo "NEWFILENAME: ${NEWFILENAME}"
       NEWFILENAME="`printf %05d ${GCOUNTER}`.jpg"
      #echo "NEWFILENAME: ${NEWFILENAME}"
       mv "${GFOLDERIN}"/"${LFILENAME}" "${GFOLDERIN}"/"${NEWFILENAME}"
       mv "${GFOLDERIN}"/"${LFILENAME}" "${GFOLDERIN}"/"${NEWFILENAME}"
      let GCOUNTER=`expr ${GCOUNTER} + 1`
      #echo ${GCOUNTER}
  done
  done


=== What it does ===
=== 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>.
* <del>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></del>
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>00001.jpg</tt>, which makes it easy to digest for <tt>ffmpeg</tt> using <tt>-i "%05d.jpg"</tt>


----
----

Latest revision as of 23:42, 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}"
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