maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   [Help] Rename Script for Camera Application (https://talk.maemo.org/showthread.php?t=17207)

cybergypsy 2008-02-26 12:38

[Fixed] Rename Script for Camera Application
 
Hi Folks

I am using the Nokia Camera application to take snaps and upload them to twitxr.com but the filenames are strangely formatted which makes finding and storing them differcult.

A file named 43_03_18-250208.jpg was taken on 25th February 2008 at 18:03:43.

I would like some help in writing a bash script to rename the same file to 20080225_180343.jpg so that the listing would be sorted automatically.

Any shell gurus in here wanna help ?

Thanks

jethro.itt 2008-02-26 14:24

Re: [Help] Rename Script for Camera Application
 
Quote:

Originally Posted by cybergypsy (Post 147929)
A file named 43_03_18-250208.jpg was taken on 25th February 2008 at 18:03:43.

I would like some help in writing a bash script to rename the same file to 20080225_180343.jpg so that the listing would be sorted automatically.

Sed is built in, at least on my N810:

Code:

#!/bin/sh
# camrename.sh - Renames Nokia Camera application pictures
# v0.01 2008-02-26 by Jussi Ylänen

while test -n "$1"; do
  OLDNAME="$1"
  NEWNAME="`echo $OLDNAME | sed -re 's/([0-9]{2})_([0-9]{2})_([0-9]{2})-([0-9]{2})([0-9]{2})([0-9]{2})/20\6\5\4_\3\2\1/'`"

  if test "$OLDNAME" != "$NEWNAME"; then
    # Remove "echo" below to really rename...
    echo mv "$OLDNAME" "$NEWNAME"
  fi

  shift
done

In the sed expression above, each ([0-9]{2}) matces two digits and remembers them, later to be referenced with \n (where n is a digit). Year is assumed to be 2000 or greater.

Copy-paste the script, save it in /home/user as camrename.sh and do:

Code:

~ $ chmod +x camrename.sh
Usage:

Code:

~ $ camrename.sh /media/mmc1/camera/images/*
When you've tried the script and seen that it appears to handle the names correctly, edit the script and remove the extra echo to really enable file renaming. No warranty!

cybergypsy 2008-02-26 14:49

[Fixed] Rename Script for Camera Application
 
Excellent , Thanks so much , I was only expecting a few helpful hints!

I've tested it and it works perfectly , you have made my day.


All times are GMT. The time now is 20:28.

vBulletin® Version 3.8.8