Author Topic: Remove _ and - from tags when writing based on file name  (Read 239 times)

avalut

  • Jr. Member
  • **
  • Posts: 26
Remove _ and - from tags when writing based on file name
« on: January 02, 2019, 05:54:22 PM »
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

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2185
Re: Remove _ and - from tags when writing based on file name
« Reply #1 on: January 02, 2019, 06:24:37 PM »
You can add s/[-_]/ /g to replace all dashes and underscores with spaces.  For example, ${filename;s/\.jpg$//i;s/[-_]/ /g}
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

avalut

  • Jr. Member
  • **
  • Posts: 26
Re: Remove _ and - from tags when writing based on file name
« Reply #2 on: January 02, 2019, 06:30:31 PM »
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

  • Jr. Member
  • **
  • Posts: 26
Re: Remove _ and - from tags when writing based on file name
« Reply #3 on: January 02, 2019, 06:34:40 PM »
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

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2185
Re: Remove _ and - from tags when writing based on file name
« Reply #4 on: January 02, 2019, 07:12:24 PM »
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.

Code: [Select]
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
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

avalut

  • Jr. Member
  • **
  • Posts: 26
Re: Remove _ and - from tags when writing based on file name
« Reply #5 on: January 02, 2019, 07:20:40 PM »
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

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 13989
    • ExifTool Home Page
Re: Remove _ and - from tags when writing based on file name
« Reply #6 on: January 02, 2019, 09:10:17 PM »
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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

avalut

  • Jr. Member
  • **
  • Posts: 26
Re: Remove _ and - from tags when writing based on file name
« Reply #7 on: January 03, 2019, 04:08:38 AM »
Hi Phil,
Slightly confused as it has the -sep " " command in. do I need to add it again in the string?

Stephen Marsh

  • Sr. Member
  • ****
  • Posts: 210
Re: Remove _ and - from tags when writing based on file name
« Reply #8 on: January 03, 2019, 06:21:20 AM »
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!
« Last Edit: January 03, 2019, 07:15:57 AM by Stephen Marsh »

avalut

  • Jr. Member
  • **
  • Posts: 26
Re: Remove _ and - from tags when writing based on file name
« Reply #9 on: January 03, 2019, 06:34:04 AM »
Hi Stephen,
The files have the following fields

Artist
Creator
Subject
Title
Copyright

avalut

  • Jr. Member
  • **
  • Posts: 26
Re: Remove _ and - from tags when writing based on file name
« Reply #10 on: January 03, 2019, 06:42:50 AM »
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

  • Sr. Member
  • ****
  • Posts: 210
Re: Remove _ and - from tags when writing based on file name
« Reply #11 on: January 03, 2019, 06:45:39 AM »
I was hoping for the full tag and value, such as:

Code: [Select]
[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
« Last Edit: January 03, 2019, 06:58:51 AM by Stephen Marsh »

Stephen Marsh

  • Sr. Member
  • ****
  • Posts: 210
Re: Remove _ and - from tags when writing based on file name
« Reply #12 on: January 03, 2019, 06:47:30 AM »
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

  • Jr. Member
  • **
  • Posts: 26
Re: Remove _ and - from tags when writing based on file name
« Reply #13 on: January 03, 2019, 06:53:56 AM »
testimage is the folder, I am trying to change about 2600 images (but only one currently in testimage) if that makes sense

avalut

  • Jr. Member
  • **
  • Posts: 26
Re: Remove _ and - from tags when writing based on file name
« Reply #14 on: January 03, 2019, 06:55:15 AM »
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.