I need help with a regular expression that selects all text before the first hyphen in a bunch of filenames. My aim is to move the files into a New Folder with the Users Name, a sub-folder with the Project Name, another sub-folder with the file extension.
i.e.
Steve Dave Jones - Big Project - Useful Stuff.txt --> Steve Dave Jones\Big Project - Useful Stuff\txt\Steve Dave Jones - Big Project - Useful Stuff.txt
Dave Jones - Minor Project.dwg --> Dave Jones\Minor Project\dwg\Dave Jones - Minor Project.dwg
The filenames all follow one of four patterns, see below.
[ul][i]Steve Smith - Project Name - More Info 23.txt
Steve Smith - Project Name 23.txt
Steve Jon Smith - Project Name 12 - Data Sheets.dwg
Steve Jon Smith - Project Name.dwg[/i]
(Names have been changed to protect the innocent)[/ul]
The first block is always text. The second and third blocks can be a mixture of text and numbers.
The following Regular Expression works on the files with a single hyphen but those with two hyphens.
Old name: b - (.).(.)[/b]
New name: \1\\2\\3\\1 - \2.\3
Type: Regular Expression
I'm sure I've read about this on the forum someone before but I can't find anything now. hopefully I've explained everything well enough as well.
I'm in the same boat. I have a rename that needs to find the first "double space" as in " ".
I am getting there. As I understand, you need to anchor the first occurrence of " - ". And the whole search.
Drat. I wanted to go and get my examples, to show that it need a "?" somewhere in the string, but I fell over a crash that I reported last week and haven't had time to pursue.
You might like to search for the message with the search "Regex (everything after second " - ")
[quote]by playful
p.s.:
The last post was the "why".
For my taste, I would probably go for something like:
pattern: (?:.?\s-\s){2}(.)
Regex (everything after second " - ")
Rename Regexp Pattern="[^-]-[^-]-(...)" to "\1"
[/quote]
Not what you are after, but maybe a few clues.
Search for the source of this snippet that I filed away.
But I suspect that one of those ever helpful regex jockeys will dive in with the answer you want. I just like to work it out for myself so that I understand what I am doing.
I need help with a regular expression that selects all text before the first hyphen in a bunch of filenames. My aim is to move the files into a New Folder with the Users Name, a sub-folder with the Project Name, another sub-folder with the file extension.
...
[/quote]
This is better done with a substitution since your output requires adding additional components depending upon the captures (so simple pattern matching alone won't work).
Use this as a Rename script in Script mode. Just check Script mode, and paste the code below. Set Old Name/New Name both as *. Save it as a preset for later use.
Thanks Michael, Playful's post seems to do what I want. I just need need a bit of time to digest the information, so for now, I will ignore this post until I work out a solution. Is it sad that I'm getting quite hooked on this Reg Exp stuff?
MrC... your script works perfectly...thank you. I still want to go away and work out the RegExp though.
I'm tiring to do some very simple search's. But. The term RegExp got me interested in this post. I have a program I have not used called RegexBuddy. regexbuddy.com/ seems to offer a lot of help with RegEXCp. I might be way off. Just wanted to help if I can.
Bob
I am currently going through some of my old topics that I responded to. This is one I am going to spend some time with, I see a lot of value here. I just would like to pass on one thing that became apparent to me that I was not expecting. it's how they placement of the"" affects any filename.
Filenamee: 58blueford.jpg
By placing "" I end up creating folders.
Rename file name: 58\blue\ford
Result: Folder's
\58\blue\ford With a filename called (.jpg) within the folder called ford.
I found this to be very interesting and was not aware of this capability. I'm not sure if this capability comes from Opus or Windows all I know is that it works.