Main Menu

Newer Than New Newbie

Started by Saltrams, March 05, 2020, 08:27:29 AM

Previous topic - Next topic

Saltrams

Today I learnt to install exiftool & use my first basic command:

exiftool -EXIF:XPComment="TestChange" c:\nameofdirectory\IMG_4627.jpg

This made me unbearably smug but pride came before the fall & I have just spent 4 hours searching the resource material to find the answer to what I suspect is a ludicrously simple task to those in the know, namely how to achieve;

Adding a "text&number" combo to the XPComment field of all the jpg files in a given directory, thereby achieving consecutive comments numbering to each file in the folder so that the XPComment reads:  Saltrams0001, Saltrams0002, Saltrams0003 and so on for each file.

I'm only going to be doing basic operations with exiftool for quite a while so I was hoping for an idiots guide to the basic commands but I haven't been able to find such a thing. Is there one?

Thank you in advance for any assistance.

Sorry, forgot the Win10 OS and the 11.87 exiftool version!

Phil Harvey

This isn't trivial, so I'm not surprised you couldn't figure this out.  I think you want a command something like this:

exiftool "-xpcomment<Saltrams${filesequence;$_=sprintf('%.4d',$_+1)}" DIR

You may also want to use the -fileorder option to order the files by name or date, depending on what you want the sequence numbers to be ordered by.

- 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 ($).

Saltrams

Thank you. A lot to work on there. Never mind, life is for learning new stuff. Thanks again.

Saltrams

Some tinkering later...I think I'm almost there.

Is there a way to stop the incremental numbering being 0001? The numbers I want to use are already pre defined and start from 01240, so I am now getting 012400001 & onward

I'm sorry I used the Saltrams001 in my example, I was trying to keep things simple  :-[

Phil Harvey

Sorry, I don't understand what you want.  Please give a specific example.

- 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 ($).

Saltrams

And I'm sorry for being unclear. Your voluntary help is so much appreciated.
Right:

I have copied 21 jpg image files to a temporary directory so I can tinker with exiftool without destroying anything (just thought I'd start with that to save you adding any warnings!)
The files are named thus: Z:\Laura\Pictures\ExiftoolPractice\2004-02-DD #### Saltrams01240 to 01261.jpg (where DD is varying days, #### are file numbers 0001 to 0021 that will remain unchanged. The Saltrams01240 - 01261 is what I want to replicate to the comments field).
Your code achieved entries in the comments field that read Saltrams012400001 - 012400021, whereas what I want is the same number as in the filename.


Now that I have had to explain it, I'm wondering if being able to copy that portion of the filename to the comments field wouldn't be a more logical option.

Phil Harvey

OK, try this:

exiftool "-xpcomment<${filename;$_=(/(Saltrams\d+)/ ? $1 : undef)}" DIR

This should extract "Saltrams####" from the file name and put it into the XPComment.

- 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 ($).

Saltrams

Indeed it does.
Thank you very much, I would never have got there myself (or as near to never as makes no difference).
Best regards, Laura.

Saltrams

Things have been going swimmingly with the command line instruction that Mr Harvey provided. I've added comments to lots of files but today I hit a snag.
It seems that I can only add one quantity of text to the XPComments field, either by using Exiftool and the command as instructed
exiftool "-xpcomment<${filename;$_=(/(Saltrams\d+)/ ? $1 : undef)}" DIR or by bulk editing in Win10 File Explorer via properties/details/comments. One new comment will overwrite existing comments.
So, question is, what do I need to add to the command I was given (or how to tinker with it to allow for additional comments to be inserted), please?

Decided to add an example, as I have form for lack of clarity:
The code copies the filename into the comments field. I want to add the text "Developer CD 707412 724585" to the copied filename, preferably after it but it doesn't really matter. If I'm lucky, the 2 comments will be separated by punctuation. The quotation marks are not required.

Phil Harvey

Try this:

exiftool "-xpcomment<${filename;$_=(/(Saltrams\d+)/ ? $1 : undef)}" "-xpcomment<$xpcomment ${filename;$_=(/(Saltrams\d+)/ ? $1 : undef)}" DIR

The second argument will override the first and add to the existing XPComment if it exists.

You might want to add some punctuation in between, but in my command I have only added a space.

- 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 ($).

Saltrams

Crikey! You had given a reply even as I was still editing my question. Thank you soooo much; I'll try it right now.

Phil Harvey

I'm not sure exactly what you want to do.

To add "Developer CD 707412 724585" to the existing comment, separated by a comma:

exiftool "-xpcomment<$xpcomment, Developer CD 707412 724585" DIR

or to add it to the comment when copying from the filename:

exiftool "-xpcomment<${filename;$_=(/(Saltrams\d+)/ ? $1 : undef)}, Developer CD 707412 724585" DIR

or to add both of these to the existing XPComment

exiftool "-xpcomment<$xpcomment, ${filename;$_=(/(Saltrams\d+)/ ? $1 : undef)}, Developer CD 707412 724585" DIR

or to handle the case where the XPComment may not exist already

exiftool "-xpcomment<${filename;$_=(/(Saltrams\d+)/ ? $1 : undef)}, Developer CD 707412 724585" "-xpcomment<$xpcomment, ${filename;$_=(/(Saltrams\d+)/ ? $1 : undef)}, Developer CD 707412 724585" DIR

- 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 ($).

Saltrams

Precision is key isn't it? I'm learning that very quickly. Ironically, in the Arts world (which is really where I belong) my composition and writing skills have been commended but they are sorely lacking when science is the driving force.

All of your kindly proffered examples will go towards my compilation of commands to work with. So, for learning purposes because I want to be able to compose my own commands logically from extrapolating existing known commands; I'm thinking that exiftool "-xpcomment<$xpcomment, Developer CD 707412 724585" DIR is the basic part that instructs "add {this text} to whatever is in XPcomments already" ?

Is there a cheat sheet for basic commands? I had a root around in the wealth of sources but couldn't find the sort of thing I need. I really don't want to be the bore that just asks for help for each task  :(

Phil Harvey

Hi Laura,

The only cheat sheet for basic commands are the examples in the application documentation, but they are of limited use because the range of possibilities is just too wide to be able to provide a comprehensive set of examples.  Instead, I recommend reading the -tagsFromFile section of the documentation (specifically, the paragraph beginning with "An extension of the redirection feature...").

- 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 ($).

Saltrams

Thanks again, I will study the page(s) you suggest. I would say that I hope not to bother you again but it would be a vain hope, so until next time...
Best regards