Is it possible to update the PreservedFileName tag based on the filename?

Started by philipwalton, October 14, 2020, 02:32:50 AM

Previous topic - Next topic

philipwalton

I have a bunch of DNG files whose `PreserveFileName` tag has gotten out of sync as various Lightroom updates have rolled out over the years, and I'm trying to make them all consistent.

I have a predictably named set of files, and I'd like to update the `PreservedFileName` tag of each file based on the filename, e.g. for the file `20170429_200041_IMG_3878.dng` (with a date/time prefix), I want the `PreservedFileName` to be `IMG_3878.CR2` (e.g. the original RAW filename).

I originally thought I could do something like this, but it doesn't seem to be supported:

```
exiftool '-PreservedFileName<=%-8f.CR2' -r .
```

Is this possible to do in batch?



Luuk2005

Greetings Philip. If all the files is predictably like 20170429_200041_IMG_3878.dng, this maybe you can use..
-PreservedFileName'<${FileName;$_=substr($_,-12,-4)}.CR2'

The -12,-4 destroys the .dng extension to make $PreservedFileNames like IMG_3878.CR2
There might be better ways, but Im think this is the easiest and I think everything can work in a batch.
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7

StarGeek

Luuk2005's answer works well.  There are other ways because the Perl that exiftool runs on is very flexible, but they aren't necessarily better.

Quote from: philipwalton on October 14, 2020, 02:32:50 AM
I originally thought I could do something like this, but it doesn't seem to be supported:

exiftool '-PreservedFileName<=%-8f.CR2' -r .

The <= function is used to copy data into a tag from a separate file (see here).  The %f token (the root of %-8f) can't be used as a value to write to a tag, only as part of a format string for use with the Filename/Directory pseudo-tags or a filename format string for the -w (textout), -o (Outfile), or -TagsFromFile options.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype