#1 : 31/12-15 06:08 Leonard
Posts: 4
|
Hello,
I have a batch of files with the following naming convention: scf_E_03411_JE- The numerical portion of each file name is different. I need to copy the numerical portion of the file name (03411 in the above example) to the end of the file name so the file name will be scf_E_03411_JE-03411. Any suggestions? Thanks. |
#2 : 31/12-15 13:22 Jon
Posts: 12
|
Reply to #1:
Are there any other parts of the filename that can be numeric? |
#3 : 31/12-15 15:22 Leonard
Posts: 4
|
Reply to #2:
Hi Jon, No other parts of the filename are numeric. And I should tell you that the original file name is actually numeric (i.e. 123456.pdf). I used the Add method to add "scf_E_" in front of the file name, then I used another Add method to add "_JE-" to the end of the file name. Now, I need to copy the numeric portion of the original file name to the end of the new file name. That's the part I can't figure out. The new file name should be "scf_E_123456_JE-123456.pdf". |
#4 : 02/01-16 14:31 Jon
Posts: 12
|
Reply to #3:
Sorry for the delay, came up with this yesterday but forgot to post it here. Method: Replace. Text to be replaced: ([^0-9]*)([0-9]+)(.*) Replace with: \1\2\3\2 And use regular expressions has to be checked, apply to name only. |
#5 : 05/01-16 20:51 Leonard
Posts: 4
|
Reply to #4:
It worked! Thanks so much! Can you walk me through the actions behind the code? |
#6 : 08/01-16 17:47 Jon
Posts: 12
|
Reply to #5:
Sure thing. It's a regular expression, and since the file names originally were only numeric, so the pattern is broken down into "sub strings". scf_E_123456_JE-.pdf The first part (sub pattern): ([^0-9]*) Matches from the beginning of the file name and matches anything that isn't a digit (ie, 0-9 ^^) so it will match: "scf_E_" The next part: ([0-9]+) Matches all the digits, needing 1 or more. So it will match '123456', since the '_' doesn't match the pattern. Next: (.*) Matches everything else. Since all the sub-patterns are within parenthesis, it means that we can use them in the replace portion. Each sub pattern can be referenced by `\#` so the first would be `\1`, etc. So for the replacement part, we want to keep them all, but add the numerical part again at the end, so we'll do \1\2\3\2 Since `\2` is the part we want repeated at the end, we put it in again at the end of the filename after keeping the rest the same. |
#7 : 13/01-16 23:34 Leonard
Posts: 4
|
Reply to #6:
Thank you, Jon. |