Renaming files II

Started by tps800, July 11, 2018, 07:34:06 AM

Previous topic - Next topic

tps800

Hi!

I'd like to rename files in a way:

DSCxxxxx.jpg -> 20180710-081122-000_<Nickname>.jpg

if and only if <Nickname> is set.

I tried with

exiftool "-tagsfromfile @" -d "%Y%m%d-%H%M%S%%-.3c_${Nickname;}.%%le" "-filename<CreateDate" -ext JPG -ext jpg .

This works as expected, as long as ${Nickname} is defined. But if Nickname is not defined it does:

DSCxxxxx.jpg -> 20180710-081122-000_.jpg


What isn't what I'd like too have. I tried to calculate a Nickname from ${Creator}:

exiftool "-Filter=~ m/\b\w/g" "-tagsfromfile @" -d "%Y%m%d-%H%M%S%%-.3c_${Source;}.%%le" "-filename<CreateDate" -ext JPG -ext jpg .

But this did not filter ${Creator} as expected. This perl filter is expected to extract every first character in every word, then create a new string out of it: "Carl Philip Montenegro" -> CPM,

I'd expected to get:

DSCxxxxx.jpg -> 20180710-081122-000_CPM.jpg


if ${Creator} where "Carl Philip Montenegro".

But this did not do what I'd like to have done. I'd wanted to skip renaming if ${Nickname} is not defined. Or even better: in case nickname is not defined take ${Creator}, extract the first Character from each word and then take that as nickname.

Any idea how to get that?

StarGeek

Since you want different things to happen depending upon if a tag exists, then the first thing to look at is note #1 under -TAG=VALUE option.  You set a tag to your default and then have alternates following depending upon if a tag exists.

First, as far as I can tell.  You're not copying in tags, just renaming, so the -TagsFromFile @ is removed (and you shouldn't enclose the @ part with the -TagsFromFile in quotes, they are two separate arguments).

The -d option can't include a tag name, so the tag and the extension variable will be moved from there to the part where the filename copy happens.

-Filter isn't an option.  The argument is -api "Filter=<some code>".  Also, using the match regex by itself will not give you the results you want.  You would need to either capture the matches and then use the perl join command or use regex substitution to remove the rest of the text.  But you only want that if Nickname doesn't exist  So you don't want to use filter, just advanced processing on that part of the command.

The -ext option is case insensitive, so you only need one of them.

So here's the command I suggest.  Test it out first as I haven't tested it myself
exiftool -d "%Y%m%d-%H%M%S" "-filename<${CreateDate}%-.3c.%le" "-filename<${CreateDate}%-.3c_${Creator;$_=join('',m/\b(\w)/g)}.%le" "-filename<${CreateDate}%-.3c_$Nickname.%le" -ext jpg FileOrDir
"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