Insert a Counter at position In the middle of the file name

I got some files that look something like this:
Title A2d3y
Title Dad3a NOTE
Title C5adF
I want to remove the five digits after title and replace it with a counter and keep the Note comment.
Title 01
Title 02 NOTE
Title 03
This woudl be easy without the extra NOTE at the end, but I want to keep it.

Can the "Title" and "Note" contain spaces?

If so, I think this is not sufficiently defined for it to work, since it won't be clear which part is the "five digits" in some cases. Even if the titles can't contain numbers, the "five digits" are hex and there are five letter words that are valid hex values.

For example:

Example title faced faded extra note at end

Is that:
Example title faced faded extra note at end
Example title faced faded extra note at end

If the title and/or note can contain numbers as well as spaces then it will be even harder for it to get things right.

Perhaps I wasn't clear that my examples are not generic I meant them as actual specific examples.
In this example all three file names all started out the same length, there were just those five random looking digits, and I added the word Title to the front and the world NOTE to the end of one of them. I didn't assign the five digits the Internet site did and I am trying to preserve the original download sorting order but make the numbering more obvious and shorter. I want to delete the characters 7-11, then preserve the original order and insert an automatic counter at position 7. This requires inserting a counter between two words, but the same number of characters from the left, in the second file.

Now my problem is I'm wondering if this is turning into a problem for Regex and I can't get it to ever work when I've tried and don't care to try to learn again.

I'm spitballing ideas, now I wonder if it would be easier to put the counter at the end of all the files, then remove the five characters I want removed, then move NOTE to the end as actually Note is some weird tagging system I use and doesn't change.

You may want to try using this:

Old name : (.*?) ([a-z0-9]{5})(.*)

New name : \1 [#]\3

Thanks for trying and I appreciate all your effort, but it didn't work. I still wound up with counters at the end of every file. I hate Regex. I can never get it to work and I'm never going to remember how to write it and don't need it often enough to put the effort into learning it. Heck, it was an ordeal for me just to copy the code you wrote over into Dopus. I'm convinced the Rexex in my copy of Dopus is broken as I couldn't get much simpler code I wrote when I did try to learn it to work. Don't try to fix anything as I don't have any urgent need for it, I was doing it partially as an logic puzzle.

Make sure Preferences / Miscellaneous / Advanced: [Compatibility] regex_style is set to the default C++ TR1 (ECMAScript).

Other than that, there's no way to break the regex code. :slight_smile: There are many flavours of regex though, so they can work slightly differently between any two programs.

I have added the values for old and new name in the original post. I had forgotten to copy them, sorry about that.
What a pity that it didn't work for you, although I used the reference values that you used at the beginning, and you can also see the results.

I thank you very much that code worked!
I copy and pasted the code this time, but I think I may have been dumb and tried it on another dummy set of files with different names. I do want to say Regex still intimidates me completely but with a success I might be tempted to try again. The odd thing about Regex is it sure looks like that odd advance code Microsoft Word used in it Find and Replace dialog.

I was about to post then remembered I saved the Regex I copied by hand yesterday and compared it to the code you posted today I just copied. They were different. I missed a space between \1 and [#]
It stuff like this that means I'll never be a coder. That and 67 year old eyes.
Thanks again!

1 Like

Today errante posted it, and I copied and pasted the code and it worked this time. Read about it below if you want. I may try using Regex again just for "fun."

How many questions is too many? I'm working on thousands of photos some I'm constantly find out things about Dopus or wanting to do something clever ever because I need to or suspect Dopus can do. I've always said if the process I'm doing with files(s) seems relatively straight forward, I'm pretty s Dopus can do it for me.

1 Like