rename raw photo and the xmp's

Hi,

i want to rename my cr2 + xmp files of my raw photos…
How can i rename *.cr2.xmp to a equal name of *.cr2 ?
the trick is that i renamed the *.cr2 with “exiftool -d “%Y-%m-%d-%-4f.%%e” “-filename<CreateDate” ./”
exiftool grabs the taken date of the photo and rename it.

so, i want to rename my cr2 file but also the *.cr2.xmp file and they must have a equal name.
for people that doesn’t know what xmp files are, is a sidefile for the raw’s, here created by AfterShotPro.
who knows how i can do that, thx?

starting:
IMG_2012.cr2
IMG_2012.cr2.xmp

finish:
2012-07-31-0001.cr2
2012-07-31-0001.cr2.xmp

I do not think that what is in the file has any influence on how you name them.
When you agree with that, my idea is that you want the following:

You have a bunch of files in a directory where the names of the files all end in .cr2.xmp. You want the .cr2 removed from those names (the rest staying equal. I have the next statements, but be carefull, they do not check if the newe name does allready exist in that directory. If that is the case, that older file will be overwritten!


#!/bin/bash
#
# This removes the string .cr2 from all filenames that end in .cr2.xmp
# This script works in the current/working directory,
# thus first cd to the place where you want this to be done.
#
for F in *.cr2.xmp
do      mv ${F} ${F%.cr2.xmp}.xmp
donefor F in *.cr2.xmp; do mv ${F} ${F%.cr2.xmp}.xmp; done

I did a small test with the above, but you are responsible for everything you run on your system :wink:

PS, you do not realy need a script, you can also type:

for F in *.cr2.xmp; do mv ${F} ${F%.cr2.xmp}.xmp; done

Well, to avoid typos, better copy/paste it.

no that is not what i want :frowning:

i have the follow:

import the raw’s with gphoto
“IMG_2559.cr2” rename it to “20120731_105121_IMG_2559_5D.cr2”
that’s for a timeline, because we have other camera’s :wink:

then do the stuff in raw converter AfterShotPro & export in JPG.

After rawconverting i have:
20120731_105121_IMG_2559_5D.jpg
20120731_105121_IMG_2559_5D.cr2
20120731_105121_IMG_2559_5D.cr2.xmp

so now i do the follow
rename all the photo’s with exiftool on date & number (to year-month-date-0001.xxx)

  • JPG DIR → 2012-07-31-0001.jpg
  • RAW DIR → - 2012-07-31-0001.cr2

the above i can do it but…
now i what to rename the xmp also like “2012-07-31-0001.xmp”

I value that you explain a bit of background because that is allways usefull to get a better picture about what you want. But in fact it is completely uninteresting how you got those files, or what is in them. I tried above to define what you want exactly to be done. And I failed. Partly I think because there is to much talking about files that are not involved at all.

I will try to describe anew what I think that you want. This contains some questions where it is not clear what you want. Please add, change this definition until it is 100% clear to both of us…Then I will try to program that in bash statements.

You have a directory with files named following the pattern 20120731_105121_IMG_2559_5D.cr2.xmp.

  1. the first 8 characters are the date in yyyymmdd format (thhis is my guess, you did not explain it);
  2. the character _;
  3. the time in 6 characters in hhmmss format (again, my guess)
  4. the characters IMG;
  5. a number of four digits (no idea what it represents)
  6. the character _;
  7. two characters ?? (what can it be)
  8. the characters .cr2;
  9. the characters .xmp;

You want them renamed to:

  1. the same date as 1, but in the format yyyy-mm-dd;
  2. the character -;
  3. a number of 4 digits, but is that allways 0001 or is there some algorithm to calculate this?
  4. the characters .xmp

Please , just explain clearly what you want: I have this file “20120731_105121_IMG_2559_5D.cr2.xmp”. I want this file 2012-07-31-0001.cr2.xmp. … or this one 2012-07-31-0001.xmp? Or are we supposed to guess something else?

yes the files are:
yyyymmdd_hhmmss_IMG_2559_5D

IMG_2559 → original name that comes from camera
5D → type of camera ( this is one from the Canon EOS 5DII)
*.xmp → sidefile of rawconverter Extensible Metadata Platform - Wikipedia, the free encyclopedia (all the changes are stored inside xmp because there is no write possible in raw (cr2) files.

the renaming (for jpg and raw) have to be done with exiftool
because exiftool looks into jpg en raw for the taken date of the photo. that stands for “2012-07-31”
but with xmp files there is no info that exifool can use

in big lines i have now the follow script:

the problem:
coming home with 100 raw photos / make a selection 20/100
copy the 20 JPG + RAW (+ *.cr2.xmp) file to collection under certain requirements.

1/ have a dir with finished photos (jpg’s) → right click in dolphin, action “to collection”
2/ copy to jpg in dir to “collection dir JPG”
3/ searching the raw (cr2) files of the jpg’s and copy into “collection dir RAW”
4/ rename the jpg’s into 0001.jpg, 0002.jpg … 0020.jpg
5/ adding date to jpg’s with exiftool "2012-07-31-0001.jpg
6/ moving jpg’s with exifttol into sub dir date "JPG/2012-07-31/2012-07-31-0001.jpg
7/ rename the cr2’s into 0001.cr2, 0002.cr2 … 0020.cr2
8/ adding date to raw’s with exiftool "2012-07-31-0001.cr2
9/ moving cr2’s with exiftool into sub dir date "RAW/2012-07-31/2012-07-31-0001.cr2

the (amateur) script :shame:
http://users.telenet.be/photo-memories/img/service-foto_om_weg_te_schrijven

don’t shoot me dead over the written code :wink:

Hallo heelstraf,

Ik geloof niet dat je mij begrijpt. Ik wil niets weten over fotos’, al de dingen die je gelukt zijn en al die andere bestanden, enz. Ik wil naar het abstracte probleem.

Ik begrijp bijv. dat je van 20120731_ naar 2012-07-31- wilt, dat is geen probleem. En ik begrijp ook dat je de laatste vier tekens .xmp wilt handhaven, ook geen probleem. Maar hoe kom je van 105121_IMG_2559_5D.cr2. naar 0001? Moet dat domweg worden gedaan? Dat is namelijk je voorbeeld! Dat kan alleen goed gaan als er maar één foto per dag is gemaakt. Zo niet dan blijft alleen de laatste van 31 juli 2012 bewaard als 2012-07-31-0001.xmp

dacht al dat je ook nederlands spreekt, dat zal vlotter gaan :wink:
ik wil alle bestanden hernoemen naar de genomen datum van de foto (2012-07-31) + volgnummer geven.
het lukt bij jpg en cr2 files omdat ik daar gebruik kan maken van exiftool, die kijkt in de bestanden naar “creatdate”
nu wil ik de *.cr2.xmp files ook hernoemen zelfde naam als de *.cr2
eigenlijk moet ik een manier vinden om tijdens het hernoemen van de *.cr2 files direct ook de *.cr2.xmp te hernoemen met dezelfde naam.

voor het komen aan 0001, 0002, 0003 doe ik eerst:

n=$volgnummerjuist for i in * do n=$((n+1)) nn=printf "%04d" $n mv $i ./$nn.cr2 done

daarna voor het komen aan 2012-07-31, waarbij “%-4f” de voorbije 0001 blijft:

exiftool -d “%Y-%m-%d-%-4f.%%e” “-filename<CreateDate” ./

Beste heelstraf,

Als je dit liever in het Nederlands doet, open dan aub een thread in het Nederlandse deel.
Ik heb dit williswaar in het Nederlands gedaan omdat ik geen grip kreeg op je Engels, maar het is natuurlijk zeer onbeleefd om dat hier te doen.

To all:
I switched to Dutch because I thought that there was a language barrier here. I now adivsed the OP to go for the Dutch forums where I will try to help him.

I applogize for posting here in a language most of you will not understand.

Ok, i found the solution for my problem.

IMG_2012.cr2 → ./Y-M-D/Y-M-D-0001.cr2
IMG_2012.cr2.xmp → ./Y-M-D/Y-M-D-0001.cr2.xmp

n=1
for i in *.cr2
do

  n=$((n+1))
  nn=`printf "%04d" $n`
  mv $i ./$nn.cr2
  mv $i.xmp ./$nn.cr2.xmp
  
    for f in $nn.cr2
    do
    exiftool -d "%Y-%m-%d-%-4f.%%e" "-filename<CreateDate" $f
    xmp=`find -name *$nn.cr2`
    rename "$nn.cr2.xmp" "$xmp.xmp" "$nn.cr2.xmp"
    exiftool "-Directory<DateTimeOriginal" -d "%Y-%m-%d" $xmp
    xmp2=`echo "$xmp" | awk -F\.cr2 -F"-" '{print $1 "-" $2 "-" $3}'`
    mv $xmp.xmp ./$xmp2
    done

done

When it does what you want, Congratulations!