extracting a substring of the folder name

#1 : 14/07-25 23:39
Dataguy
Posts: 2
Greetings - I'm requesting some help with how to do the following:

I want to append a substring from the <FolderName:1> tag, to my filename. For example, given the following folder name:

thisisvariablestring - thisisvariablestring - 1469660590 - this is variable length

I would like to append 1469660590 to the filename. The value might be shorter or longer, but it will ALWAYS be between the leading "-" and the trailing "-". I also do not want the space before the 1 or the space after the 0 to be included. There will ALWAYS be those spaces before and after in the folder name.

To recap, it's the value between the 2nd and 3rd "-", without the spaces. There could also be more "-" after the 3rd one, but I'm not interested in anything beyond the 3rd "-".

Can someone help? Thank you in advance.

edited: 15/07-25 02:06
#2 : 15/07-25 03:28
Delta Foxtrot
Posts: 523
Reply to #1:

Hi Dataguy,

There are several ways to do what you want, but the quickest and easiest is to just use this script in a script method:

n = item.newBasename ;
fn = app.parseTags('<Foldername>') ;
fp = fn.match( /^[^\-]+\-[^\-]+\- (\d+)/ ) ;
return n + fp[1];

Open an empty ARen, add an empty script method, and paste the four lines into the main script window. Click "Apply script", add your files, and ba-da-bing.

That does exactly what you asked for, just appends that number from your folder name right on the the end of the filename(s). If you want a divider character between the original and new part, reconfigure the last line like this (I'm using a dash as an example):

return n + "-"+fp[1];

As for other ways to do it, you may want to instead use a series of non-script methods. In that case you can do this:

ADD method:
Add: !<Foldername>
At index: 0
Backwards: CHECKED
Use regular expressions: unchecked
Apply to: Name

REPLACE method:
Replace: \![^-]+-[^-]+- (\d+) - .*$
Replace with: $1
[no spaces. Or use "-$1" if you want, for example, a dash between old and new]
Case sensitive: unchecked
Use regular expressions: CHECKED
Apply to: Name

If the part you want to append is not always a number we'll have to rework this a little; just let us know..

Best,
DF
#3 : 15/07-25 10:47
Dataguy
Posts: 2
Reply to #2:
This works PERFECTLY! Thank you very much, DF