#1 : 04/05-24 06:09 Wayne Wickson
Posts: 5
|
Somehow when using Power Rename several hundred filenames in our database got modified incorrectly. Here are three incorrect examples: 2016_08_16 SMITH John16_09_16 CW.jpg - 2017_12_13 JONES William17_12_17 CW.jpg - 2018_12_18 BROWN George18_12_18 CW.jpg. A space and the number 20 got chopped off of what was supposed to be a representation of a date. The filenames should have looked like this: 2016_08_16 SMITH John 2016_09_16 CW.jpg - 2016_12_13 JONES William 2017_12_17 CW.jpg - 2018_12_18 BROWN George 2018_12_18 CW.jpg. I have tried many combinations, including using REGEX suggested by ChatGPT, but nothing has worked without modifying 16-17-18 in other locations in other filenames. The issue seems to center around only modifying the number (16-17-18) near the end of the filename in the second "date", perhaps by capturing only the number immediately after the letters [A-Ma-m] but NOT the letters themselves. Any suggestions?
|
#2 : 04/05-24 08:02 Delta Foxtrot
Posts: 324
|
Reply to #1:
Hi Wayne, Yeah, that's what you get for playing with toys... LOL Ok, PowerToys. You realize that you can undo renames in Power Rename, right? I know, sometimes you don't notice stuff like that in the heat of office battle. :) Anyway, couldn't be easier, as long as all files conform to your examples (and I'm assuming here that Smith, Jones and Brown were each separate filename examples, not one long filename). You need one replace method: Text to replace: ^([^ ]+)([^\d]+) (just one space, inside the first parentheses pair and after the caret "^ ") Replace with: $1$2 20 (just the one space, inside the replacement, not on the outer ends) Case sensitive: No Regular expressions: YES Apply to Name The first container ($1 in the replace) tells ARen to gobble up all characters from the start of the filename that aren't spaces, and stop at a space. The second says take everything not a number and stop (that gets the name and the spaces). The replace just consists of putting those two containers back, followed by the space and the "20". Using your examples, that worked for me. Best of luck to ya, let us know how it goes. (And don't forget to check the preview before you pull the trigger! :) Best, DF |
#3 : 04/05-24 18:08 Wayne Wickson
Posts: 5
|
Reply to #2:
Thanks for the script. It worked great. :-) Are there any resources for REGEX that you have found particularly effective in your work? |
#4 : 05/05-24 00:13 Delta Foxtrot
Posts: 324
|
Reply to #3:
Now there's a question whose answer could fill volumes. Regex has been around since the 1950s, based on linguistics regular language concepts amplified greatly in the '40s. I started working with them in the early '80s in my work in Unix tech support. There are at least eight distinct flavors of regex, and probably hundreds of Internet resources for each flavor, so nothing will be canonical, nor would you want to delve that deeply unless computer sciences were your forte. I use resources from Jan Goyvaerts, an amazing guy who is an expert on all formulations of regular expressions, an author of books on the subject, and the driving force behind a series of software tools that both employ regex and explain it. He has an amazing free site, https://www.regular-expressions.info/ (you'll get used to the rather garish color scheme before you know it... I didn't say the guy was a graphic artist :) that has more information than you or I will ever need on the subject. Including a tutorial that with a little effort will guide you through and beyond the basics and past anything useful in tools like renamers or programmers' text editors. If you want to truly "understand" regex, pay attention to the section on how regex engines work; if you understand that you'll be ahead of 99% of the millions of folks that use regex on a daily basis. I bet you wish you'd never asked, right? :) But maybe Miguel or Styb, or Kim Jensen (the author of this amazing program) would chime in with their favorites. I'm sure everyone conversant in regex has their own personal picks. Best, DF |
#5 : 05/05-24 13:00 Wayne Wickson
Posts: 5
|
Reply to #4:
Thanks so much! You are a real asset on this site. :-) |