Author Topic: Variable Substring Extraction  (Read 1913 times)

Offline AnnieP

  • Member
  • **
  • Posts: 59
    • View Profile
Variable Substring Extraction
« on: March 30, 2022, 06:52:28 PM »
2022_03_29 Houston _DSC4301.ARW
2022_03 Austin _DSC4303-Edit.tif
2022_03 Dallas-Fort Worth _DSC4303-Edit-Edit.tif

Is there any way using variable substring extraction (or some other method) that I can extract the right-hand portion of the above filenames. I want to extract everything from “_DSC” and to the right.
There is no common number of characters to the left of it and I’m not sure what I can count to/from.

Any suggestions?  Many thanks.
« Last Edit: March 30, 2022, 07:08:13 PM by AnnieP »

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 24764
    • View Profile
    • Camera Bits, Inc.
Re: Variable Substring Extraction
« Reply #1 on: March 30, 2022, 07:54:38 PM »
Annie,

2022_03_29 Houston _DSC4301.ARW
2022_03 Austin _DSC4303-Edit.tif
2022_03 Dallas-Fort Worth _DSC4303-Edit-Edit.tif

Is there any way using variable substring extraction (or some other method) that I can extract the right-hand portion of the above filenames. I want to extract everything from “_DSC” and to the right.
There is no common number of characters to the left of it and I’m not sure what I can count to/from.

Use: {filenamebase:-8}

That should do it.

HTH,

-Kirk

Offline AnnieP

  • Member
  • **
  • Posts: 59
    • View Profile
Re: Variable Substring Extraction
« Reply #2 on: March 30, 2022, 09:08:13 PM »
Thank you much for the reply.

Well, it did work, kind of. I want to retain the file extension. Using the {filename base: -8} gives me just the _DSCxxxx. And that's if there were no "Edit" in the name.

Some of the names might have three Edit's in them: 2022_04_34 _DSC3819-Edit-Edit-Edit.ARW, in which case I get "dit-Edit".

If there are two "Edit' in the name, 2022_04_34 _DSC3819-Edit-Edit.ARW, I also get the "dit-Edit".

If there is one "Edit", 2022_04_34 _DSC3819-Edit.ARW, I get "819-Edit".

And some of the leading dates are year, month, and day, as the example; and others are merely year and month (2022_02).

There's just a lot of variation. The only common thing is the "_DSC" string in the middle.

Is there by chance some solution that would fit all cases?

Offline Mick O (Camera Bits)

  • Camera Bits Staff
  • Hero Member
  • *****
  • Posts: 525
    • View Profile
    • Camera Bits
Re: Variable Substring Extraction
« Reply #3 on: March 31, 2022, 09:24:11 AM »
If you want to delete everything from “_DSC” and to the right (but keep the extensions) I might suggest trying Find & Replace with a "regular expression."

1. Because there is no 'UNDO' in file renaming, you might want to consider applying a Metadata Template to the files and put {filenamebase} into an unused filed like "Supp Cat 1" That way if you accidentally do something to the filenames that you can't recover from, you would be able to rename the files at least back to their original state before you started fixing them. :-)

2. If you run Edit > Find and Replace with these settings, it will find "DSC_" and everything after it and replace it with nothing -- but should leave the extension. 

In the Find field:  _DSC.*
In the replace field: Leave empty
Check the box for "Filename"
Check the box for "Grep"  (When using Grep the .* roughly means "any number of characters") 

Find and Replace works on items in the current Contact Sheet. You can choose to run it on all the items in the Contact Sheet OR to run it only on items you have selected. Keep that in mind. (Edited to add: Also, it looks like you have an extra space in all those filenames before _DSC. You can add that space in the "Find:" field if you want.)

"Regular expressions" (like .*) are used in programming and other apps, not just Photo Mechanic. They can get very (VERY) complex, so if you want to learn more about them you could get started here: https://regexone.com/ but the basic use above should work without having to learn the whole regex system.

Go slow at first, and try with some small subset of files to make sure it is doing what you expect.  I hope this helps.

Mick
 
Mick O
Camera Bits

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 24764
    • View Profile
    • Camera Bits, Inc.
Re: Variable Substring Extraction
« Reply #4 on: March 31, 2022, 09:26:33 AM »
Annie,

Well, it did work, kind of. I want to retain the file extension. Using the {filenamebase:-8} gives me just the _DSCxxxx. And that's if there were no "Edit" in the name.

You can use {filename} instead, but you'll have to deal with differences in extension length.

There's just a lot of variation. The only common thing is the "_DSC" string in the middle.

Is there by chance some solution that would fit all cases?

No, not with Variable Substring Extraction.  You could use Find and replace to remove that detritus on the filenames and then do an additional rename.

Are you trying to rename files or generate some kind of report?  Without knowing your end goal, it's hard to offer you the correct advice.

-Kirk

Offline AnnieP

  • Member
  • **
  • Posts: 59
    • View Profile
Re: Variable Substring Extraction
« Reply #5 on: March 31, 2022, 10:48:16 AM »
I have used PM for years, but only superficially. I'm trying to become better acquainted with it and branching into PM+ as well. It's a great program and I couldn't do without it.

That said, I'm really new to a lot of its powers. I rename all my photos, prefixing the camera filename (_DSCxxxx.ARW) with a date and location: 2023_03_29 Wharton, if it's a single day; 2022_03 Austin if it's a multiple day trip, which gives me 2023_03_29 Wharton _DSCxxxx.ARW, with a space between the two sections.

The filename can be modified by the number of edits it has undergone. Thus the "-Edit" or "-Edit-Edit" or "-Edit-Edit-Edit." (I don't think there are ever more than three.) So I end up with this filename: 2023_03_29 Wharton _DSCxxxx-Edit.ARW or 2023_03_29 Wharton _DSCxxxx-Edit-Edit.ARW or 2023_03_29 Wharton _DSCxxxx-Edit-Edit-Edit.ARW. Or if it is unedited, just 2023_03_29 Wharton _DSCxxxx.ARW.

What I was looking for was something that would retain everything from the "_DSC" and to the right, stripping off the prefix I added.

Before you tell me to just not add it in the first place, let me tell you why I was trying to do this. Some of these filenames are so long that when I am viewing my contact sheets the only way I can see part of the filename is to make the image larger than I really want. So I found where you can modify what is shown below the image on the contact sheet and I thought I could use the Variable Substring Extraction to pull out what I want so it would be visible when the images were a smaller size. So basically I just want to do this to display under the image in the contact sheet.

With all the variation in lengths, etc., I couldn't figure it out but thought that maybe someone who is more familiar with PM might be able to.

I should have explained more clearly initially. Hope this clarifies somewhat.

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 24764
    • View Profile
    • Camera Bits, Inc.
Re: Variable Substring Extraction
« Reply #6 on: March 31, 2022, 11:15:44 AM »
Annie,

Thank you for the additional information.  If you're only wanting this for display purposes, I do not have a solution for you.  If you're willing to rename the files and then get better results for display purposes then I could assist you.

I would take an approach of eliminating the variable length issue from your filenames.  If everything had an edit and a count instead of repeating the term, then you could have:

No edits so far:
2023_03_29 Wharton _DSCxxxx-E00.ARW

One edit so far:
2023_03_29 Wharton _DSCxxxx-E01.ARW

Two edits so far:
2023_03_29 Wharton _DSCxxxx-E02.ARW

Ninety-nine edits so far:
2023_03_29 Wharton _DSCxxxx-E99.ARW

One hundred or more edits would not be supported, nor would it ever happen in practice.  If this approach is interesting to you and you're willing to rename your existing filenames and adopt it moving forward then it's possible to use Variables Substring Extraction to get the display that you want.  We can discuss this further if you'd like.

-Kirk

Offline AnnieP

  • Member
  • **
  • Posts: 59
    • View Profile
Re: Variable Substring Extraction
« Reply #7 on: March 31, 2022, 11:45:53 AM »
Thank you very much. I'm afraid I just don't want to actually rename the files in reality. I guess I'll just continue looking at them as they are, and if it gets too bothersome, I'll just increase the size of the images!

Thanks again for the help. And I did learn something.


Offline AnnieP

  • Member
  • **
  • Posts: 59
    • View Profile
Re: Variable Substring Extraction
« Reply #8 on: March 31, 2022, 12:23:43 PM »
You know what would be really, really nice? To be able to change font size in the thumbnail labels.

Any chance?

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 24764
    • View Profile
    • Camera Bits, Inc.
Re: Variable Substring Extraction
« Reply #9 on: March 31, 2022, 12:45:55 PM »
You know what would be really, really nice? To be able to change font size in the thumbnail labels.

Any chance?

Not likely in the PM6 release.  Quite likely in the PM7 release.

-Kirk

Offline AnnieP

  • Member
  • **
  • Posts: 59
    • View Profile
Re: Variable Substring Extraction
« Reply #10 on: March 31, 2022, 01:59:14 PM »
That's excellent news! Look forward to it.

Thanks, everyone, for all the help.