Rename cr2 file (camera RAW file) if jpg was renamed

Hi,
I can't figure out how to do this. It's hard to describe in English but I try.

I'm always renaming all my camera files with this preset "{shootingtime}.jpg". But lately I had started to shoot jpg + RAW so I need to also rename *.cr2 files. But *.cr2 files don't understand "{shootingtime}", so I was renaming them with "{createddate} {modifiedtime}". But this pattern is different for *.jpg and *.cr2 files which is causing sorting issues (I have set off thumbnailing for raw files to raise processing speed ) so I can't exactly know which .cr2 file corresponds to .jpg.

So my question is IS there a way to select only jpg files and rename them with {shootingtime}.jpg pattern AND if corresponding cr2 file exist then rename it to the same name which jpg file had just been renamed? :open_mouth:

Thanks you.

Well, as is often the case with this sort of thing - there are probably several other ways to do it - but here's a way it can be done with a rename script:

[code]cd {s}
Rename FILEINFO TYPE=files FROM *.JPG TO {shootingtime}
@script vbscript
Option Explicit

Function Rename_GetNewName(strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName)
Dim DEBUG, vbQuote, finfo, DOpusRTPath, commandLine, shell, strFileNameBase
' Change DEBUG flag to TRUE to debug without actually executing the commandLine
DEBUG = FALSE
vbQuote = Chr(34)

' Take the {keywords} tag data sent in by strNewName, and store in local var
finfo = strNewName

' Set strNewName to an empty string so that Opus does not rename the file
strNewName = ""

' Change the path below if you haven't installed Opus to the default location:
DOpusRTPath = "C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe"

' Strip JPG extension from filename, to use on CR2 files
strFileNameBase = Left(strFileName,Len(strFileName) - 3)

' Build FIRST command line:
commandLine = vbQuote & DOpusRTPath & vbQuote & " /cmd " &_
"Rename FROM " & vbQuote & strFilePath & "" & strFileNameBase & "" & vbQuote &_
" TO " & vbQuote & strFilePath & "" & finfo & ".
" & vbQuote

' Create the req'd shell object needed to 'Run' the commandLine
Set shell = CreateObject("WScript.Shell")

' If debugging, look for messages in Opus by turning on Logs->Other Logs under the Help button on the default Menu toolbar
if DEBUG then
DOpus.OutputString "Command:" & vbCrLf & commandLine & vbCrLf
else
shell.Run commandLine,1,1
end if
End Function[/code]
...you can add this code to a button and try it out.

Note: this script will use the base name of each JPG file in the folder in which it is run... you don't need to "select" any files... Also, the rename will rename any files with the same base name and ~whatever extension. If you know you'll ONLY ever have jpg and cr2 files in the folder you'll run this from, then that should be ok. I had some unexpected results trying to refine the rename command to make it more specifically operate ONLY on jpg and cr2 files... :frowning:. Hopefully it's useful as at least a starting point.

{shootingtime} should work with .cr2 files (or at least works with the ones I have; there may be more than one type), so it's worth double-checking that the .cr2 files were not being skipped due to something else.

For example, if you were renaming from *.jpg to {shootingtime}.jpg then that would skip all the .cr2 files because they do not match *.jpg

Also make sure the enable file information fields option is turned on, else {shootingtime} won't work at all.


If {shootingtime} doesn't work with your .cr2 files then there is still an easy way to do this.

The rename matching filenames as one option exists so that when one file is renamed, others which only differ by extension will also be renamed in a similar way.

The only caveat is that the second file has to be below the one that's being renamed normally, in the list of files. Since xyz.cr2 will normally sort above xyz.jpg, you'll need to reverse-sort the list of files in the lister before clicking the Rename button. (We might improve that in the future, but it's how things work right now.) From there, you can do this:


Note that in this second example, I am using *.jpg as the pattern, but the .cr2 file is still being renamed because rename matching filenames as one is turned on.

steje, your script is almost perfect, the only downside is that I cannot undo after renaming is done and this is crucial for me.
I didn't realized such in-button renaming scripts are possible, this script will probably help me in some cases.
Thanks :thumbsup:

leo, "rename matching filenames as one" option did it :thumbsup: . Somehow this it slipped my eyes.
It seems the .cr2 files from 5D mark II can't show {shootingtime} info.
Thanks.

FWIW, {shootingtime} seems to work with the few 5D Mk 2 test files that I have. Maybe they're not all the same, though.


Hm, something might be wrong here.

Photoshop is able to show all EXIF data and I have the latest DO update installed. May be it's a different camera firmware version - on 5Dmark2 I have v2.1.2, can't say about 550d.