Bulk renaming photos

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post please read this

Bulk renaming photos

Postby Husse on Sat Oct 13, 2007 4:14 pm

I import from two digital cameras (one camera and one phone)
Datestamp on the phone is accurate and I try to keep it correct in the camera too
I want to rename the pictures with date+time as that makes much more sense than DSC001 and the like
I've seen solutions that are a bit towards this, but not a satisfactory solution
Then looking at a photo of my wife or me it's easy to see how much we age :)
Image
Don't fix it if it ain't broken, don't break it if you can't fix it
Husse
Level 21
Level 21
 
Posts: 19710
Joined: Sun Feb 11, 2007 7:22 am
Location: Near Borås Sweden

Linux Mint is funded by ads and donations.
 

Postby scorp123 on Sat Oct 13, 2007 4:48 pm

Try this:
Code: Select all
apt-cache search rename | sort | more
... and then take a good look at the list you get. There are a few candidates that you could check out .... e.g. gwenrname, krename, mrename, renameutils, purrr ...... Take a closer look at those packages, e.g.
Code: Select all
apt-cache show purrr
... I am sure one or the other package should be able to do what you want.

Or you write a nice shell script :D
User avatar
scorp123
Level 8
Level 8
 
Posts: 2287
Joined: Sat Dec 02, 2006 4:19 pm
Location: Switzerland

Postby Husse on Sun Oct 14, 2007 8:17 am

Or you write a nice shell script

I could probably write that and more, but it takes time to learn - lets say python - and then write it :)
I don't want to spend all my time tied to the computer - my wife needs some attention too :lol:
Image
Don't fix it if it ain't broken, don't break it if you can't fix it
Husse
Level 21
Level 21
 
Posts: 19710
Joined: Sun Feb 11, 2007 7:22 am
Location: Near Borås Sweden

Postby scorp123 on Sun Oct 14, 2007 10:26 am

Husse wrote: but it takes time to learn - lets say python - and then write it :)
Yeah right. :lol: We write complicated Python programs (and we'd need to learn the language first :roll: ) for stuff the shell can already do more efficiently out of the box and right away. :shock:

Very efficient :lol:

Seriously: All you need is a decent for ... do ...; done loop in bash and then have it auto-move your files into their new names. It would of course help if you e.g. had provided a listing of the files so we can see their names :wink:
User avatar
scorp123
Level 8
Level 8
 
Posts: 2287
Joined: Sat Dec 02, 2006 4:19 pm
Location: Switzerland

Postby newW2 on Sun Oct 14, 2007 11:40 am

Like this? Got it from some how-to script writing site, and it works well with wild cards.

#!/bin/bash

search=`gdialog --title "Rename files" --inputbox "Search for" 200 450 2>&1` || exit
replace=`gdialog --title "Rename files" --inputbox "Replace with" 200 450 2>&1` || exit

path=`echo -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | head -n 1 | sed 's/[^\/]*$//'`

while [ $# -gt 0 ]; do
newname=`echo "$1" | sed -e "s/$search/$replace/g"`
mv "$path$1" "$path$newname"
shift
done
User avatar
newW2
Level 6
Level 6
 
Posts: 1081
Joined: Fri Apr 06, 2007 10:24 am
Location: USA

Postby Husse on Sun Oct 14, 2007 11:57 am

Thanks both of you :)
gwenrename does the job - just have to convince it to use it's option for profiles and I'm done...
@scorp
There are all sorts of names for the existing pictures.....
dsc+number image+number "normal descriptive name"
Image
Don't fix it if it ain't broken, don't break it if you can't fix it
Husse
Level 21
Level 21
 
Posts: 19710
Joined: Sun Feb 11, 2007 7:22 am
Location: Near Borås Sweden

Postby scorp123 on Sun Oct 14, 2007 12:53 pm

My HP cameras always produce files that start with the letters hpim.... something. So if I wanted to do something like you I'd do it like this.

Original directory listing (produced with 'ls -A1'):
Code: Select all
...
hpim2043.jpg
hpim2044.jpg
hpim2045.jpg
hpim2046.jpg
hpim2047.jpg
hpim2048.jpg
hpim2049.jpg
hpim2050.jpg
hpim2052.jpg
hpim2053.jpg
hpim2054.jpg
hpim2055.jpg
hpim2056.jpg
hpim2057.jpg
hpim2058.jpg
hpim2059.jpg
hpim2060.jpg
hpim2061.jpg
hpim2062.jpg
hpim2063.jpg
hpim2064.jpg
hpim2065.jpg
hpim2066.jpg
hpim2067.jpg
...


This simple 'for' loop here (yes, this program is a 1-liner!) will copy them to their new filenames using their time stamps:
Code: Select all
for d in `ls -A1 hpim* | cut -c -8`; do NEWFILEEND=`ls -Al $d* | awk '{ print $6,$7}' | tr " " "_"`; cp $d"_"$NEWFILEEND".jpg"; done


Directory listing afterwards:
Code: Select all
...
hpim1587_2007-01-24_20:41.jpg
hpim1589_2007-01-24_20:41.jpg
hpim1590_2007-01-24_23:21.jpg
hpim1591_2007-01-24_23:22.jpg
hpim1592_2007-01-24_23:22.jpg
hpim1593_2007-01-24_23:22.jpg
hpim1594_2007-01-26_06:31.jpg
hpim1595_2007-01-26_06:32.jpg
hpim1596_2007-02-01_21:32.jpg
hpim1597_2007-02-01_21:32.jpg
hpim1598_2007-02-01_21:33.jpg
hpim1599_2007-02-01_21:33.jpg
hpim1601_2007-02-01_21:33.jpg
hpim1602_2007-02-01_21:33.jpg
hpim1603_2007-02-02_02:55.jpg
hpim1605_2007-02-02_02:59.jpg
hpim1610_2007-02-02_03:06.jpg
hpim1613_2007-02-02_03:07.jpg
hpim1614_2007-02-02_03:08.jpg
hpim1617_2007-02-03_00:31.jpg
hpim1619_2007-02-03_00:31.jpg
hpim1620_2007-02-03_00:32.jpg
hpim1621_2007-02-03_00:32.jpg
hpim1625_2007-02-03_22:27.jpg
hpim1627_2007-02-03_22:28.jpg
hpim1629_2007-02-04_00:37.jpg
hpim1632_2007-02-04_00:55.jpg
hpim1634_2007-02-04_05:53.jpg
hpim1635_2007-02-04_05:53.jpg
hpim1636_2007-02-14_06:59.jpg
hpim1637_2007-02-14_06:59.jpg
...


All done in the the shell with standard shell commands :D
User avatar
scorp123
Level 8
Level 8
 
Posts: 2287
Joined: Sat Dec 02, 2006 4:19 pm
Location: Switzerland

Postby Husse on Mon Oct 15, 2007 7:15 am

Nice
We have two cameras
one producing DSC+number one producing Imag+number
and added to that there were some files renamed to things like Kerstin (my wifes name) with flowers
Gwenrename fixed it as soon as I removed all double files
Image
Don't fix it if it ain't broken, don't break it if you can't fix it
Husse
Level 21
Level 21
 
Posts: 19710
Joined: Sun Feb 11, 2007 7:22 am
Location: Near Borås Sweden

Linux Mint is funded by ads and donations.
 

Return to Other topics

Who is online

Users browsing this forum: No registered users and 6 guests