From 9c4cd95d78e9ddbe5a1b77a5b66e0a2459aba6df Mon Sep 17 00:00:00 2001 From: fliegerjohn Date: Sat, 11 Mar 2023 20:31:45 +0100 Subject: [PATCH] first commit --- README.md | 15 +++++++++++++ name2timestamp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 README.md create mode 100755 name2timestamp diff --git a/README.md b/README.md new file mode 100644 index 0000000..0a52e72 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +Simple script to rename multimediafiles to the shotdate. + +You need to install "exiftool" on your computer! + +Usage: + +./name2timestamp /path/to/dir/with/files/ + +Config: + +Please change the Variable "ending" to your needs. +for example: ending=MTS to ending=jpg + + +This scipt should rename every file "exiftool" can work with... diff --git a/name2timestamp b/name2timestamp new file mode 100755 index 0000000..709a9f9 --- /dev/null +++ b/name2timestamp @@ -0,0 +1,57 @@ +#!/bin/bash + +# +## Variables +# + +# Dir of files +dir="$2" + +# + +# +## Main +# +printhelp() { + echo "**** +You need to install 'exiftool' on your computer! + +Usage: + +./name2timestamp 'fileending' /path/to/dir/with/files/ + +For 'fileending' you can set everything exiftool can handle with, like 'jpeg' or 'MTS'. +(And this script can find it in the given dir... :o)) +**** + " + exit 0 +} + +convertfile() { + +# Check for exiftool + +if ! [ -x "$(command -v exiftool)" ]; then + echo 'Error: exiftool is not installed. Please install exiftool to use this script!' >&2 + exit 1 +fi + +# Rename file + +for file in "$dir"/*."$ending" +do + # Getting new name for file + shottime=`exiftool -"DateTimeOriginal" -fast -R -d "%Y-%m-%d %H:%M:%S%z" -s -S "$file"` + newname=`date -d "$shottime" "+%Y%m%d_%H%M%S"` + # Rename file + mv "$file" "$dir"/"$newname"."$ending" + echo "renamed "$file" to "$newname"."$ending"" + +done +} + + +#Print help if $1 is "--help" otherwise set it to fileending and start converting +if [[ "$1" = "--help" ]]; then printhelp; else ending="$1" && convertfile; fi + +