How to rename RAW+JPEG files?

Asked by Alphazo

Hi,

I extensively use pyRenamer for my camera pictures. In the past I would either shoot JPEG or RAW so renaming was simple. Since I got my new camera that produces nice B&W JPEG I switch from JPEG only to JPEG+RAW depending of the day.
I end up with a weird filename scheme that I would like to harmonize with pyRename.
Is there a way to do the following renaming?

P00105.JPG -> 2009-11_Zoo_001.JPG
P00106.JPG -> 2009-11_Zoo_002.JPG
P00107.JPG -> 2009-11_Zoo_003.JPG
P00107.RW2 -> 2009-11_Zoo_003.RW2
P00108.JPG -> 2009-11_Zoo_004.JPG
P00109.JPG -> 2009-11_Zoo_005.JPG
P00109.RW2 -> 2009-11_Zoo_005.RW2

Thank you
Alphazo

Question information

Language:
English Edit question
Status:
Answered
For:
pyRenamer Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
epictete (p-latreyte) said :
#1

I think this would do the job :

{imageyear}-{imagemonth}_Zoo_{num3+1}

with "Conserve the extension" checked.

Revision history for this message
Alphazo (alphazo) said :
#2

Than you for the hint. I guess I must be using your settings wrongly as it didn't work for me.

I'm using pyRenamer 0.6.0 with the following files:
- P00215.JPG
- P00216.CR2
- P00216.JPG
- P00217.JPG
- P00218.CR2
- P00218.JPG

In the first tab (rules) I entered :
- Rule for original filename: {X}
- Rule for renamed filename: 2010-10_Zoo_{num3+1}

And finally I checked the "Conserve the extension" box. The preview shows:

- 2010-10_Zoo_001.JPG
- 2010-10_Zoo_002.CR2
- 2010-10_Zoo_003.JPG // Should be ".._002.JPG"
- 2010-10_Zoo_004.JPG // Should be ".._003.JPG"
- 2010-10_Zoo_005.CR2 // Should be ".._004.CR2"
- 2010-10_Zoo_006.JPG // Should be ".._004.JPG"

Thank your for your help.
Alphazo

Revision history for this message
epictete (p-latreyte) said :
#3

Hi Alphazo, I understand what you want.

I believe you must do the job in 2 steps using the files filter on the right side of the software using first *.jpg as the filter, renaming your files, then using *.cr2 as the filter and renaming the other files.

By the way, {imageyear}-{imagemonth}_Zoo_{num3+1} tells the software to find the year and month of the photo in its exif datas so that you don't have to give the date yourself!

With 2010-10_Zoo_{num3+1} the date will always be 2010-10 for all the photos!

Tell me if all this is what you need.

Revision history for this message
Alphazo (alphazo) said :
#4

The two-pass approach won't work as I will loose the link between the JPG and RAW.

On the same following file set.
- P00215.JPG
- P00216.CR2
- P00216.JPG
- P00217.JPG
- P00218.CR2
- P00218.JPG

If I filter *.JPG first I would get :
- 2010-10_Zoo_001.JPG
- 2010-10_Zoo_002.JPG
- 2010-10_Zoo_003.JPG
- 2010-10_Zoo_004.JPG

However when filtering to *.CR2 I would get:
- 2010-10_Zoo_001.CR2 // should be _002.CR2
- 2010-10_Zoo_002.CR2 // should be _004.CR2

Unfortunately the CR2 files no longer matches the JPG ones.

I don't know if that can help but here are the cases that can and cannot happen:
- JPG only : this case can happen
- JPG + CR2 : this case can happen
- CR2 only : this case cannot happen, there is always a JPG files next to the CR2 file.

I've tried about half a dozen of renaming tools without success. I'm not a script guru but I guess this can be done via bash, awk ...

Maybe you can add this idea to the wishlist for a future release of pyRenamer.

Thank you
Alphazo

Revision history for this message
epictete (p-latreyte) said :
#5

Ok that's my fault : I didn't understand that the raw and jpeg filenames must stay linked ; I'm sorry.

Well I've just tested a solution with 4 of my photos but it is incomplete for the numeration: I can't have it to begin at 001, it's always from 215 (or anything else...) but maybe it could be enough for you:

POO215.CR2 POO215.JPG POO216.CR2 POO216.JPG

gives:

2009-12_Zoo_215.CR2 2009-12_Zoo_215.JPG 2009-12_Zoo_216.CR2 2009-12_Zoo_216.JPG

You must use the "Images" tab for {imageyear} and all exif datas to work (if you want the date to come from the exif datas, else you can use the first tab).

First line: POO{#}.{C}

Second line: {imageyear}-{imagemonth}_Zoo_{1}.{2}

About the wishlist, I'm afraid there is a mistake for I'm not a developer but a simple user like you!

Revision history for this message
Alphazo (alphazo) said :
#6

Hi,

Thanks for the tip. That's a good start. As a less elegant way I was thinking about having a batch file to create dummy .CR2 files for every single .JPG that is in the directory and that doesn't exist yet. Then I could easily mass rename the whole thing in two passes and then in the end delete the files with a size of 0 byte.

I'll keep you posted on my findings.
Alphazo

Revision history for this message
epictete (p-latreyte) said :
#7

It would be a big job to delete all the dummy files in a big lot of photos Alphazo.

I think that the good way would be to be able to minus all the numbers by 214 for example so that 215 becomes 001, 216 becomes 002, etc ; maybe using sed but this exceeds my competence!

It would be fine if somebody else with bigger knowledge than me could answer!

Perhaps you could ask the question on forums about sed?

Whatever, I would be happy to know if you find a solution.

Good luck Alphazo and happy wishes from France!

Revision history for this message
Alphazo (alphazo) said :
#8

Thanks epictete and "Bonne Année" from France too ;)

Revision history for this message
epictete (p-latreyte) said :
#9

Hi Alphazo, I've submitted your problem on this forum :

http://www.unix.com/unix-dummies-questions-answers/127018-substract-certain-number-names-several-files.html

The solution was immediately given by an obliging geek named Scrutinizer :

If the names of your photos are this type and beginning from 215 :
- P00215.JPG
- P00216.CR2

then the following script will transform them to :
POO001.CR2 POO001.JPG POO002.CR2 POO002.JPG

ls | while read name
do
  ext=${name##*.}
  first=${name%.*}
  pre=${first%%[0-9]*}
  nr=${first##*[^0-9]}
  newnr=$(printf "%03d" $((nr-214)))
  mv "$name" "${pre}${newnr}.${ext}"
done

Just copy this in a text file, name it namesubtract, copy it in /usr/local/bin, add (in the permissions tab) execute permissions.
In the folder containing your photos, open a terminal and type namesubtract.

I've tested this in a temporary folder with some tests files and it works perfectly ; you'd better do the same!

You'll have, of course, to adapt the script and change the number to decrease (here 214) for the beginning number of your photos minus 1.

Revision history for this message
epictete (p-latreyte) said :
#10

So that you don't have to adapt the script to the first number of the photos, it's better to add the 3 first lines:

[CODE]echo -n "Enter the number of the first photo: "
read num
ls | while read name
do
  ext=${name##*.}
  first=${name%.*}
  pre=${first%%[0-9]*}
  nr=${first##*[^0-9]}
  newnr=$(printf "%03d" $((nr-num+1)))
  mv "$name" "${pre}${newnr}.${ext}"
done[/CODE]

Can you help with this problem?

Provide an answer of your own, or ask Alphazo for more information if necessary.

To post a message you must log in.