String substitution in -XMP-crs:RAWFileName

Started by c++, November 01, 2019, 07:12:03 AM

Previous topic - Next topic

c++

Hi Phil, not sure whether I'm being stupid or this is a bug we'll see...

I'm using exiftool in a makefile's .PHONY: run on an undetermined number of files. What breakes that are spaces and braces in filenames do I have a 'make prep' step to put placeholders in their stead and a 'make clean' step to remove 'em again. Not elegant but it works fine.

I was originally using  exiftool '-XMP-crs:RAWFileName<$${directory}/$${filename},' ... but directory resolves to ./ in this use case and I need the full path to the file.

So I'm getting it in make by
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(dir $(mkfile_path))

and am then using
exiftool '-XMP-crs:RAWFileName<$(MKFILE_DIR)$${filename}' ...
That gets me what's being processed below:
<crs:RawFileName>/Volumes/Untitled/RAW/LEICA_sp@ce_X_sp@ce__o-br@ce_TYP_sp@ce_113_c-br@ce_.DNG</crs:RawFileName>

So much for the prelude...

Now what I figured I'd do was replace the placeholders with spaces and braces on the meta data again and I thought this may be the way:
exiftool '-XMP-crs:RAWFileName<$(MKFILE_DIR)$${filename}' '-XMP-crs:RAWFileName<$${XMP-crs:RAWFileName;s/_sp@ce_/ /g;s/_o-br@ce_/(/g;s/_c-br@ce_/)/g}'

What I get is puzzling me:
<crs:RawFileName>L9600255.DNG</crs:RawFileName>
Where does that come from?

So, is it a bug or am I plainly being stupid ;-)

Phil Harvey

Let's take a step back and use the ExifTool "FilePath" tag to get the full path:

exiftool '-XMP-crs:RAWFileName<$${filepath}' ...

Does that solve your problem(s)?  (I didn't read the 2nd half of your post)

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

c++

Thanks Phil, exiftool '-XMP-crs:RAWFileName<$${filepath}' ... was a good starting point as it simplifies what I had. Turned out that I really sought
exiftool '-XMP-crs:RAWFileName<$${filepath;s/_sp\@ce_/ /g;s/_o-br\@ce_/(/g;s/_c-br\@ce_/)/g}'
I hadn't escaped my @s before but also had misconceived something I think. I thought that I could write to a tag, in this case XMP-crs:RAWFileName and direcly thereafter pull its contents to edit like so:
exiftool '-XMP-crs:RAWFileName<$${filepath}' '-XMP-crs:RAWFileName<$${XMP-crs:RAWFileName;s/_sp \@ce_/ /g;s/_o-br \@ce_/(/g;s/_c-br \@ce_/)/g}'
Turns out that doen't work. When I try that I still get the
<crs:RawFileName>L9600255.DNG</crs:RawFileName> which was a puzzle before. I don't think this is a bug I think it comes from earlier in my processing sequence and since what you pointed me to works it's good enough for me. Thank you so much!

Phil Harvey

The right side of "<" always refers to the tags from the original image.  So I think you want this:

exiftool '-XMP-crs:RAWFileName<$${filepath;s/_sp \@ce_/ /g;s/_o-br \@ce_/(/g;s/_c-br \@ce_/)/g}' ...

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).