News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Remove _ and - from tags when writing based on file name

Started by avalut, January 02, 2019, 05:54:22 PM

Previous topic - Next topic

avalut

Hi,

I have been slowly getting there with adding meta data to a load of images in a folder.

Say first file name is:

Lot_439_1-Heathrow-T1-Aviation-Glass-Desk.jpg

I can with this command
perl c:\windows\exiftool.pl -P -r "-title<${filename;s/\.jpg$//i}" -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

Write Lot_439_1-Heathrow-T1-Aviation-Glass-Desk to the title tag.

I would like to remove to write the title as below:

Lot 439 Heathrow T1 Aviation Glass Desk

I then need to do the same for the Subject tag and comments tag.

Also then apply a fixed name "Auctioneersvault Ltd" to the Copywrite and Author tag

Once I get this working I will attempt to call it from within a UBot exe, which currently downloads all the images and names them on download from 1.jpg etc to the above.

sorry if I asked 3 things at once.

Andrew

StarGeek

You can add s/[-_]/ /g to replace all dashes and underscores with spaces.  For example, ${filename;s/\.jpg$//i;s/[-_]/ /g}
* 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).

avalut

I tried this command and it didn't remove them ?

perl c:\windows\exiftool.pl -P -r "-subject<${filename;s/[-_]/ /g/\.jpg$//i}" -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

avalut

Sorry, going blind tried
perl c:\windows\exiftool.pl -P -r "-subject<${filename;s/\.jpg$//i;s/[-_]/ /g}" -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

its replacing the spaces with a ;and a space

StarGeek

I just copy/pasted your command and it worked, though maybe not how you want it.  Separating on space puts Lot, 439, and 1 as individual keywords, where I think you would actually want "Lot 439 1" as a single keyword.

C:\>exiftool -overwrite_original -P -r "-subject<${filename;s/\.jpg$//i;s/[-_]/ /g}" -sep " " -ext jpg "Y:\!temp\bb\Lot_439_1-Heathrow-T1-Aviation-Glass-Desk.jpg"
    1 image files updated

C:\>exiftool -g1 -a -s -subject "Y:\!temp\bb\Lot_439_1-Heathrow-T1-Aviation-Glass-Desk.jpg"
---- XMP-dc ----
Subject                         : Lot, 439, 1, Heathrow, T1, Aviation, Glass, Desk
* 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).

avalut

I need it to remove the , its putting in then its how I am after it.

so
Lot, 439, 1, Heathrow, T1, Aviation, Glass, Desk

To become
Lot 439 1 Heathrow T1 Aviation Glass Desk

Phil Harvey

The ", " is just the default separator for list items.  XMP:Subject is a list-type tag, and list items are stored individually.  You can add -sep " " to the extraction command to display them with just spaces between them.

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

avalut

Hi Phil,
Slightly confused as it has the -sep " " command in. do I need to add it again in the string?

Stephen Marsh

#8
avalut, I don't wish to confuse things, however your request interested me...

For the first part to add the filename to the title removing underscore/hyphen/extension, I would offer the following method of combining two regular expressions together:

exiftool "-title<${filename;s/\.[^\.]+$//;s/[-|_]/ /g}" -r DIR

However I think that you will need to clarify the exact fields that you wish to write to for the Copyright and Author tag. The easiest way is to use the exiftool -a -G1 -s FILE command to list the writable tag names on a file that you know has this data.

EDIT: Ah, I now see that StarGeek has already offered a similar approach!

avalut

Hi Stephen,
The files have the following fields

Artist
Creator
Subject
Title
Copyright

avalut

This works great:
perl c:\windows\exiftool.pl -P -r "-title<${filename;s/\.[^\.]+$//;s/[-|_]/ /g}" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

and does what I want.

I cannot follow why when I change -title to -subject or comments to write the same data it just says "the system cannot find the file specified.

What am I missing?

Stephen Marsh

#11
I was hoping for the full tag and value, such as:

[IFD0]          Artist                          : Auctioneersvault Ltd
[IFD0]          Copyright                       : Auctioneersvault Ltd
[XMP-dc]        Rights                          : Auctioneersvault Ltd
[XMP-xmpRights] Marked                          : True
[Photoshop]     CopyrightFlag                   : True
[IPTC]          By-line                         : Auctioneersvault Ltd
[IPTC]          CopyrightNotice                 : Auctioneersvault Ltd
[XMP-dc]        Creator                         : Auctioneersvault Ltd
[XMP-dc]        Rights                          : Auctioneersvault Ltd
[XMP-photoshop] AuthorsPosition                 : Lot 439 1 Heathrow T1 Aviation Glass Desk
[IPTC]          By-lineTitle                    : Lot 439 1 Heathrow T1 Aviation G


Stephen Marsh

Could it be something as simple as:

perl c:\windows\exiftool.pl -P -r "-title<${filename;s/\.[^\.]+$//;s/[-|_]/ /g}" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage

vs.

perl c:\windows\exiftool.pl -P -r "-title<${filename;s/\.[^\.]+$//;s/[-|_]/ /g}" -r -sep " " -ext jpg C:\Users\Andrew\Desktop\testimage.jpg

Which does not answer why one works and the other does not...

I would remove the duplicate -r recursive command, I generally now put it directly before the target file/directory.

avalut

testimage is the folder, I am trying to change about 2600 images (but only one currently in testimage) if that makes sense

avalut

its also the same as another question I posted - one works and the other not as

perl c:\windows\exiftool.pl -artist="Phil Harvey" -copyright="2011 Phil Harvey" C:\Users\Andrew\Desktop\testimage

and it writes correctly to the file but if I change it to

perl c:\windows\exiftool.pl -artist="Silverstone Auctions" -copyright="2019 Silverstone Auctions" C:\Users\Andrew\Desktop\testimage

it come up with an error file not found, both are text fields and apart from more characters there is no change om what the command is asking unless I am missing something.

so something must be causing one thing to work and another not, what I have no idea.