You are viewing limited content. For full access, please sign in.

Question

Question

Build a Workflow to edit folder names

asked on June 12, 2019 Show version history

I have about 11,000 folders that I need to rename. Here is an example of them. 

The name on the left is the current folder name. I'm trying to get them to look like the name on the right.

100_5.-5530-1_100-1a   ->   5.-5530-1_100/1a

124_6.-6217-16_3g   ->   6.-6217-16/3g

3_1.-24-93.115_3b   ->   1.-24-93.115/3b

1_1.-16-1_2-6d.6e   ->   1.-16-1_2/6d.6e

 

I am hoping that there is an option other than pattern matching because the number of digits that need to be removed in the front of the string differs from folder to folder. If I can do something that finds the first underscore that appears from the right side, then removes that underscore along with the digits to the left of it, that would take care of the first part of the issue. 

The second part is changing the dash or underscore at the end of the string to a slash /. If there's a way for me to setup something that starts at the left side of the string, finds the first dash or underscore and changes that to a slash, that would take care of the second part of my issue. 

Any help with this issue would be greatly appreciated. 

0 0

Replies

replied on June 12, 2019 Show version history

Regular expressions in pattern matching can accomplish this despite the varying number of characters --- regular expressions are pretty flexible! I use online tools like https://regexr.com/ to experiment since it include explanations.
Note: settings in any given regular expression tool may differ from workflow defaults)

 

Since we want to replace the last dash - or underscore _, I created two patterns: one to capture the part before the final dash/underscore while also excluding the numbers and _ at the beginning, and a second pattern to capture the section after the final - or _

You could then combine the two tokens using something like this:

%(PatternMatching_BeforeSlash)//%(PatternMatching_AfterSlash)

Where the // inserts a single / , since forward slashes must be escaped using another in workflow token syntax.

 

The following pattern will return everything between the first underscore _ and the last dash -

(?:[^_]*_)(.*)(?:[-_])

(?:[^_]*_)

  • ?: specifies a "non capturing group", meaning things that will be excluded from the final match
  • ^ inside [ ] means "not the following", so [^_] will return characters except _
  • the first non-capturing group is then "everything up to and including the first _"
    • You said in your post "from the right" but your examples were from the left, so that's what I based this on

 

(.*) captures the rest of the text up until the final group, (?:[-_]), which is a non-capturing group for the last dash or underscore. (Again, I based this off of the examples, which contradicted the description). (.*) will include prior - and _ because .* is a "greedy" match.

 

The following pattern will return everything after the last dash or underscore

([^-_]+)$

The $ indicates end of the string (or end of the line, if multiple lines are involved. In your case, for folder names, they should be single lines).

[^-]+ uses the plus + to indicate "one or more". Combined with the $, it will find all characters until it hits a - or _, but starting from the end of the line.

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.