copying tags to files with different names

Started by Thomas, April 25, 2024, 02:58:34 PM

Previous topic - Next topic

Thomas

Hi, Phil,
hi, everybody,

there are so many forum posts about -tagsformfile or renaming files. But I can't get any further with my question...

I have files in two parallel directory structures. The paths are completely the same except for the second level
F:\original\country\mexico\guadalajara\
versus
F:\edited\country\mexico\guadalajara\
Now I want to copy tags from the original files to the edited files using -tagsfromfile.

However, the edited files have a five-characters suffix that is giving me trouble. There was an example in the forum with a specific letter as a prefix, e.g X. This is working fine:
exiftool -r -tagsfromfile F:/original/%:2d%.1f.%e -all:all F:\edited -if "$filename =~ /^x/"

Can you help me match files with a five-characters suffix to files without a suffix? An example pair of names would be:
F:\original\country\mexico\guadalajara\20240422#140522=DSC_0402+ancient church.jpg
and
F:\edited\country\mexico\guadalajara\20240422#140522=DSC_0402+ancient church@$§PE.jpg
(SG edit: to verify, there wasn't supposed to be a space between § and PE? I removed it because it was messing up my command when copy/pasting)

The suffix always has 5 characters and always consists of @, $, §, P, A or z (telling me in which way I edited the photos). Because the first (and only the first) character of the suffix is always @, I'm thinking along these lines, although it's not clear to me how the position of the @ sign in the filename has to be specified in the -if statement:
exiftool -r -tagsfromfile F:/original/%:2d%-1.4f.%e -all:all F:\edited -if " $filename=~/how to position @ here$/"[/tt]
I use Windows, but no batch file.

A second question: If I want to change the naming scheme, is it possible that - for example in the file 20240422#140522=DSC_0402+ancient church@$§PE.jpg - I extract the text string between the = sign and the + sign and thus return to the original file name? It seems to me that I can't use %f because the description text ("ancient church") has a variable length (as do the original file names). As an alternative, I'd like to extract the description text between the + sign and the § sign (with the original file name being of variable length; there are other original file names than "DSC_0402" with more or less than 8 characters).

After returning to original file names in the parallel directory structure for edited files, how could I copy tags from eg. guadalajara\20240422#140522=DSC_0402+ancient church.jpg to DSC_0402.jpg?

Thank you for any advice.

Thomas

StarGeek

Are there unedited files in the F:\edited\?  I'm questioning if the -if option is necessary or not.

To get the source file, you just have to remove the last 5 characters of the base name of the edited file.
-TagsFromFile F:/original/%:.5%e

Breakdown of %-.5f (see Advanced Features of the -w (-TextOut) option)
The - indicates starting at the end of the filename.  The . means removing characters from the end rather than capturing.  And 5 is the number of characters to remove.

One problem on Windows though. § is a wide, two byte character, so in my test I had to use %-.6f. It might be different for you.

Quote from: Thomas on April 25, 2024, 02:58:34 PMIt seems to me that I can't use %f because the description text ("ancient church") has a variable length (as do the original file names).

That is correct. You'll have to use
${Basename;m/=([^+]+)\+/;$_=$1}.%e

Example
C:\>exiftool "-Testname<${Basename;m/=([^+]+)\+/;$_=$1}.%e" "Y:\!temp\x\20240422#140522=DSC_0402+ancient church@$§PE.jpg"
'Y:/!temp/x/20240422#140522=DSC_0402+ancient church@$§PE.jpg' --> 'Y:/!temp/x/DSC_0402.jpg'
    0 image files updated
    1 image files unchanged


QuoteAs an alternative, I'd like to extract the description text between the + sign and the § sign

It would be about the same.
${Basename;m/\+([^§]+)§/;$_=$1}.%e

QuoteAfter returning to original file names in the parallel directory structure for edited files, how could I copy tags from eg. guadalajara\20240422#140522=DSC_0402+ancient church.jpg to DSC_0402.jpg?

That can't be done. One, there's no way to reconstruct 20240422#140522=DSC_0402+ancient church.jpg from DSC_0402.jpg. Unless there are tags already embedded that would allow it. I assume the first part before the equal is the date, but "ancient church" would have to be pulled from somewhere.  Second, the -TagsFromFile option can only used the % variables. You can't use actual tags as part of the source. 
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Thomas

Hi, StarGeek,

thanks for replying and explaining things. There are no unedited files in F:\edited\?. Each edited file (with suffix) corresponds to an unedited file (without suffix) in F:\edited\? but that's not true vice versa because not all original files have been edited. So, I guess I have to use the -if statement when copying tags from "F:\original\" to "F:\edited\"?

Concerning renaming 20240422#140522=DSC_0402+ancient church@$§PE.jpg (to DSC_0402.jpg):

${Basename;m/=([^+]+)\+/;$_=$1}.%e

works perfectly. Could you please breakdown the syntax as you did with %f?

${Basename;m/\+([^§]+)§/;$_=$1}.%e has a warning.

exiftool -r -ext jpg "-filename<${Basename;m/\+([^§]+)§/;$_=$1}.%e" F:\edited

gets:

Warning: Malformed UTF-8 character(s) - F:/edited/country/mexico/guadalajara/20240422#140522=DSC_0402+ancient church@$§oo.jpg
    4 directories scanned
    1 image files updated


Inserting \ prior to § or using the -charset option doesn't help. Nonetheless, the resulting file name is correct but without extension: ancient church@$. Can you imagine a workaround or should I replace the § sign by a more common character?

The last question maybe has been misleading. It's just a variation of the first question. So instead of using -tagsfromfile for

F:\original\country\mexico\guadalajara\20240422#140522=DSC_0402+ancient church.jpg
to
F:\edited\country\mexico\guadalajara\20240422#140522=DSC_0402+ancient church@$§PE.jpg

I would like to be able to rename the edited fils and copy tags from

F:\original\country\mexico\guadalajara\20240422#140522=DSC_0402+ancient church.jpg
to
F:\edited\country\mexico\guadalajara\DSC_0402.jpg
or to
F:\original\country\mexico\guadalajara\ancient church.jpg.

Thomas

StarGeek

Quote from: Thomas on April 26, 2024, 06:50:07 PMEach edited file (with suffix) corresponds to an unedited file (without suffix) in F:\edited\? but that's not true vice versa because not all original files have been edited. So, I guess I have to use the -if statement when copying tags from "F:\original\" to "F:\edited\"?

Not. The files in F:\original\ are not the ones being processed, and exiftool only looks in that directory for a file that matches one F:\edited\. So any number of files can be in the original dir but exiftool will never see any that doesn't have a matching edited one.

QuoteConcerning renaming 20240422#140522=DSC_0402+ancient church@$§PE.jpg (to DSC_0402.jpg):

${Basename;m/=([^+]+)\+/;$_=$1}.%e

works perfectly. Could you please breakdown the syntax as you did with %f?

RegEx is much more complex than exiftool's % variables. In this case, the constracut of m/.../ is looking for a match between the two slashes.
= matches the character = with index literally

1st Capturing Group ([^+]+)
This is the content to be captured

[^+] Match a single character not a + sign

+ matches the previous token ([^+]) between one and unlimited times, as many times as possible
This means it will match as many characters that aren't a + sign until it find one or finds the end of the string.

All of the above basically takes every character between the = and the +, captures it and saves it into a variable called $1

\+ matches the character + with literally. Probably not needed, as the above regex won't capture it, but I tend to include it as it reminds that this is capturing everything between the = and the +

All of that is a single piece of code. A semicolon ; is used to separate multiple statements.

$_=$1 $_ is the default variable in Perl. In this context, it holds the value of the tag, which in this case is Basename. This section takes the capture from the previous regex $1 and assigns it to the default variable. This changes the value of Basename

Quote${Basename;m/\+([^§]+)§/;$_=$1}.%e has a warning.

exiftool -r -ext jpg "-filename<${Basename;m/\+([^§]+)§/;$_=$1}.%e" F:\edited

gets:

Warning: Malformed UTF-8 character(s) - F:/edited/country/mexico/guadalajara/20240422#140522=DSC_0402+ancient church@$§oo.jpg
    4 directories scanned
    1 image files updated

As I said, § is a wide two byte character. The ┬º that you see is the two bytes that make up that character. You might try the options in FAQ #18, problems with special characters on the Windows command line. The only one that ever worked for me the StackExchange one.

QuoteNonetheless, the resulting file name is correct but without extension: ancient church@$. Can you imagine a workaround or should I replace the § sign by a more common character?

Personally, I avoid using the more unusual characters.  But looking that one up, Wikipedia says it's a Latin 1 character.  You might try adding the -L (latin) option. That's what I used a lot before I turned on the Unicode option in the StackExchage answer.

QuoteThe last question maybe has been misleading. It's just a variation of the first question. So instead of using -tagsfromfile for

F:\original\country\mexico\guadalajara\20240422#140522=DSC_0402+ancient church.jpg
to
F:\edited\country\mexico\guadalajara\20240422#140522=DSC_0402+ancient church@$§PE.jpg

I would like to be able to rename the edited fils and copy tags from

F:\original\country\mexico\guadalajara\20240422#140522=DSC_0402+ancient church.jpg
to
F:\edited\country\mexico\guadalajara\DSC_0402.jpg
or to
F:\original\country\mexico\guadalajara\ancient church.jpg.

You'll have to experiment with this if you want to copy tags and rename in one command. I always do my rename commands separately from any copy operations so as not to make hard to recover from mistakes.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Thomas

Hi, StarGeek,

got it. Special thanks for breaking down the RegEx.

QuoteYou'll have to experiment with this if you want to copy tags and rename in one command.

I'm not wondering how to rename and copy tags in one single command. It's just about copying the tags. Using the example of copying tags from F:\original\country\mexico\guadalajara\20240422#140522=DSC_0402+ancient church.jpg to F:\edited\country\mexico\guadalajara\DSC_0402.jpg I'm looking for something like

exiftool -r -tagsfromfile F:/original/%:2d%f=${Basename;m/=([^+]+)\+/;$_=$1}.%e -all:all F:/edited

The -if condition refers to the target file. So that's not to be used. How can I specify in another way that only DSC_0402 has to be matched in the source file?

And how would the -tagsfromfile command look like if the target file was named F:\edited\country\mexico\guadalajara\ancient church.jpg?

"DSC_0402" as well as "ancient church" exemplaryly represent strings of variable length. Other files might have strings such as "IMG_21" or "flower". So, does copying of tags fail in these cases because %f is not compatible with variable lengths of strings or can %f perhaps be replaced by a RegEx?

Thomas


StarGeek

Quote from: Thomas on April 27, 2024, 06:50:32 PMI'm looking for something like

exiftool -r -tagsfromfile F:/original/%:2d%f=${Basename;m/=([^+]+)\+/;$_=$1}.%e -all:all F:/edited

As I said, the -TagsFromFile option can only use the % variables. You can't use actual tags as part of the name of the source file.

QuoteHow can I specify in another way that only DSC_0402 has to be matched in the source file?

If the edited filename is only
DSC_0402.jpg
and the source is
20240422#140522=DSC_0402+ancient church.jpg
then there isn't a way to for exiftool to connect to a longer name. It can remove and extract parts of the edited file name or add static text only.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Thomas

Hi, StarGeek,

thank you for your message and the quick, comprehensive answers. As before, I'll find anyhow a way to organize photos using ExifTool. Editing photos is a new hobby but keyword tags are still more important to me.  :)

Best to you,
Thomas