Extracting part of a Windows JPG filename and copying into an Exif tag

Started by mpegleg, June 14, 2019, 01:48:36 AM

Previous topic - Next topic

mpegleg

I just thought I would add a quick little note. Yesterday I did a Windows sfc scannow system file scan and it DID find some corrupted system files. It fixed them and I moved on and didn't think much more of it, Except... I forgot... it only fixes Windows system files nothing else! So any apps like ExifTool could have had corrupted files, and it wouldn't know. Lesson learnt. Always restore after a BSOD.

So I'm off to do a full system restore now. Over and out. See you on the other side.  :)

ps. It doesn't take long with SSD. I'll probably be back in about 1/2 hr. *fingers crossed*
OS: Windows 11 Pro

mpegleg


I'm b a a c k. Who said time travel wasn't possible?!

Luckily I have about 3 months worth of daily restore images, so I jumped back a week, which should be well before I started getting the BSODs in the last few days caused by SageThumbs. Grrr. I'll never run that utility again. Uninstalled & DELETED!

I should have known better, because a couple of other utilities had also been behaving strangely in the last few days as well.

I just did a system file check. No errors.

I just cleared the TEMP folder, and re-installed ExifTool, so I think we're good to go.

I'll do a thorough check of Hayo Baan's code tomorrow, but it's looking good so far.

Thanks again Hayo Baan.

ps. Thanks again Phil for suggesting that my ExifTool install was corrupt. It appears it was. That makes perfect sense now. When I did my previous system image restore, obviously I didn't go back far enough, (I only went to the previous day's backup). When I think about it... the BSODs had been occuring over a period of about 3 days.
OS: Windows 11 Pro

mpegleg

Ok. So I decided to give Hayo's corrected code a quick go, and yep. It all seems to work well. The examples of where it should have ended with an empty tag, did just that. Also, there's no ExifTool error messages now with that corrupted image.

So once again.

Thanks very much.

-Paul
OS: Windows 11 Pro

Hayo Baan

Hayo Baan – Photography
Web: www.hayobaan.nl

mpegleg

Hayo, using parts of your (+ StarGeek's, and Phil's) code:


"-XPcomment<${filename; $_ =~ s/^(?:.*\[PIX\d+\]\s*)?((?:(?!modx).)*)(?:\s*modx.*|\....$)/$1/;} [${directory; use Cwd 'abs_path';$_ = abs_path($_); $_ =~ s/.*\///; $_ =~ s/^[0-9- ]*//;}. ${DateTimeOriginal;DateFmt('%Y');s/\b0+\B//g}]"



I was able to achieve this very good result:



So, it's very close to being perfect for my needs, if only those annoying extra spaces can be made to vanish into the ether.

-Paul
OS: Windows 11 Pro

Phil Harvey

Add this in an advanced formatting expression to remove extra spaces:  ;s/  +/ /g

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

mpegleg

Thanks Phil. Sorry but I'm a bit dense with all this still. Do you mind popping that into my code so I can see exactly where it should go?


Thanks :)
OS: Windows 11 Pro

Phil Harvey

"-XPcomment<${filename; $_ =~ s/^(?:.*\[PIX\d+\]\s*)?((?:(?!modx).)*)(?:\s*modx.*|\....$)/$1/;s/  +//g} [${directory; use Cwd 'abs_path';$_ = abs_path($_); $_ =~ s/.*\///; $_ =~ s/^[0-9- ]*//;}. ${DateTimeOriginal;DateFmt('%Y');s/\b0+\B//g}]"

Edit:  Hmmm.  This will remove extra spaces within the file name, but not at the end.  So maybe you need this:

"-XPcomment<${filename; $_ =~ s/^(?:.*\[PIX\d+\]\s*)?((?:(?!modx).)*)(?:\s*modx.*|\....$)/$1/;s/  +//g;s/ +$//} [${directory; use Cwd 'abs_path';$_ = abs_path($_); $_ =~ s/.*\///; $_ =~ s/^[0-9- ]*//;}. ${DateTimeOriginal;DateFmt('%Y');s/\b0+\B//g}]"
...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 ($).

StarGeek

The basic setup for the advanced formatting feature is like this:
${TAGNAME;<perl code>;<perl code>;...;}

Each snippet of perl code is separated by a semicolon and the whole thing is closed by a brace. 

You can just pop the new code at the end before the last brace.  You just have to make sure there is a semicolon before it to separate it from the previous code.

Sorry, this whole thing blew up (2 additional full pages) since I last looked and that code is getting too big for me to easily decipher.  This is actually a case where I would seriously suggest starting config file and creating a user defined tag out of it. 
* 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).

mpegleg

YAY!!!! Thank you Phil, StarGeek and Hayo Baan.

Yes, that first one Phil didn't work. I posted a reply, but quickly deleted it when I saw your edited post.

So, all good now.

Time for me to hit the sack. Midnight downunder here, and I can hardly keep my eyes open, but I can go to sleep deeply satisfied now.  :) ;D

Many many thanks. You've all made my life so much easier. My parents thank you as well, because they're the ones that will truly benefit when I show them all the nicely captioned photos.

G'nite!
OS: Windows 11 Pro

mpegleg

"-XPcomment<${filename; $_ =~ s/^(?:.*\[PIX\d+\]\s*)?((?:(?!modx).)*)(?:\s*modx.*|\....$)/$1/;s/  +//g;s/ +$//} [${directory; use Cwd 'abs_path';$_ = abs_path($_); $_ =~ s/.*\///; $_ =~ s/^[0-9- ]*//;}. ${DateTimeOriginal;DateFmt('%Y');s/\b0+\B//g}]"


Oh man! Just when I thought it was safe to go back into the water...

I just noticed when I checked some of my ExifTool outputs, that any example of filenames that would end up as only [Directory name. YEAR], had an extra hidden space before the [



Output as seen from ExifMixer:



Windows seems to hide any extra pre-spaces when it shows the result in the columns, yet they are there when you view the results with ExifTool.

What do I need to change now? Do I need to add another ;s/  +/ /g somewhere?

Note all the other examples shown in that attached pic were perfect.
OS: Windows 11 Pro

Hayo Baan

The problem is that with your current command there will always be an additional space, even if the front part is empty (you "hard-coded" that space). We can fix this by slightly modifying your code:

"-XPcomment<${filename; $_ =~ s/^(?:.*\[PIX\d+\]\s*)?((?:(?!modx).)*)(?:\s*modx.*|\....$)/$1/;s/  +/ /g;s/ +$//;s/^(.+)$/$1 /}[${directory; use Cwd 'abs_path';$_ = abs_path($_); $_ =~ s/.*\///; $_ =~ s/^[0-9- ]*//;}. ${DateTimeOriginal;DateFmt('%Y');s/\b0+\B//g}]"

The modification is that I removed the hard-coded space and added it conditionally (only when there was actually some text).
Hayo Baan – Photography
Web: www.hayobaan.nl

mpegleg

Thanks Hayo, but nope. It's the same result for me as before.

It actually put an extra space for me before the "[" in this case: "test  [Tests. 2019]"
OS: Windows 11 Pro

Hayo Baan

That can't be; it works for me. Please copy the command verbatim! Spaces are important ;)
Hayo Baan – Photography
Web: www.hayobaan.nl

mpegleg

Ok. Let me have a closer look at it. Might be something stupid I'm doing. I'll get back to you soon.
OS: Windows 11 Pro