]> piware.de Git - bin.git/commitdiff
add rename-photos
authorMartin Pitt <martin@piware.de>
Mon, 1 Aug 2011 20:23:24 +0000 (22:23 +0200)
committerMartin Pitt <martin@piware.de>
Mon, 1 Aug 2011 20:23:24 +0000 (22:23 +0200)
rename-photos [new file with mode: 0755]

diff --git a/rename-photos b/rename-photos
new file mode 100755 (executable)
index 0000000..20ff431
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+set -e
+
+num=1
+
+if [ -n "$DEBUG" ]; then
+    PREFIX=echo
+fi
+
+for f in *.JPG *.jpg; do
+    [ -f "$f" ] || continue
+    title=`exiv2 pr -Pv -gXmp.photoshop.Headline "$f"` || title=''
+    newname=`printf "%03i" $num`
+    if [ -n "$title" ]; then
+       newname="$newname - $title"
+    fi
+    newname="$newname.jpg"
+    if [ -e "$newname" ]; then
+       echo "Error: new name $newname for $f already exists, aborting" >&2
+       exit 1
+    fi
+    $PREFIX mv "$f" "$newname"
+    num=$((num+1))
+done