Notices


Reply
Thread Tools
Posts: 35 | Thanked: 18 times | Joined on Feb 2007 @ France
#1
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

Last edited by cybergypsy; 2008-02-26 at 14:50. Reason: Solution found , thanks
 
Guest | Posts: n/a | Thanked: 0 times | Joined on
#2
Originally Posted by cybergypsy View Post
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!
 

The Following 2 Users Say Thank You to For This Useful Post:
Posts: 35 | Thanked: 18 times | Joined on Feb 2007 @ France
#3
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.
 
Reply


 
Forum Jump


All times are GMT. The time now is 07:55.