How to correct the sequential number order for the selected files

example file name:
Apple (1).jpg
Apple (2).jpg
Apple (5).jpg
Apple (8).jpg
Orange (1).jpg
Orange (4).jpg
Orange (6).jpg
I want to select all the file and press the button & the button will do the result.
Apple (1).jpg
Apple (2).jpg
Apple (3).jpg
Apple (4).jpg
Orange (1).jpg
Orange (2).jpg
Orange (3).jpg
Orange (4).jpg
Is there any way to do that?

The UniqueNumbers script does not works as I want.

Problem 01. This Script Rename all Selected files to the parent1 folder name
But I want the Old name Should become the new name as I mention in my example. Apple should be Apple and Orange should be Orange in the new name.
Problem 02. This Script remove the file extension as you can see in my screenshot.
But I want the File extension should be unchanged.

Please See my Original post example in all the Apple files, The Sequential number order is not correct after Apple (2), after Apple (2), The file name is Apple (5) in my example, But That Should be Apple (3). And All the file extension should be unchanged.

Then See the Orange Files. The First file Orange has no Sequential number. but This file should be changed in to Orange (1) Then the Orange (1) Should be Orange (2) and Orange (4) Should be Orange (3) Then Orange (6) Should be Orange (4) and all the file extension should be unchanged.

Then change the Old Name and New Name patterns. You can set them to whatever you want.

Turn on Ignore Extension near the top if you want it to preserve the existing extensions.

(Or fix your Old Name / New Name patterns to preserve the extensions. Either will work. None of this is specific to the script. This is how the Rename dialog always works.)

I'm not sure what you mean here. If the issue is that the preview is showing (1) for multiple files, that's discussed in the post about the script.

Ok done it & extension problem has been solved.

But How to set the New Name Patterns for keep the Original file name in the new file name?
Regex Syntax does not work here because my Original file name not in English Language.
The Original file name in UNICODE BANGLA Language.

Regex works fine for the Example English name

Regex should work with any unicode characters, it's not limited to English.

Then plz tell me what regex should I use to keep the original file name in BANGLA file name. I have tried the same regex that's work fine in English name but it's not works in BANGLA file name.

A regex specifying [a-z] is only going to match characters from a-z. Bangla characters are outside that range, but that doesn't mean regular expressions can't work with them, it just means your regex was explicitly excluding characters outside the a-z range.

If you want to remove the (<number>) from the end of filenames that have existing numbers. A regex like this would do that:

From: (.*) \(\d+\)$
To: \1

If you then also want to add [NUM] to the end of the filenames:

From: (.*) \(\d+\)$
To: \1 [NUM]

Easy enough so far, but we aren't quite there yet, because that will skip over names that don't already have a number on the end. They don't match the From pattern, and we don't want to remove anything from them, but we still need to add [NUM] to the end of them.

Things get more complicated here, but we can solve it by making the "match everything before the number" part non-greedy (so it matches the smallest amount possible, and thus does not swallow up the number part) and making the "match the number part" optional (so things still work if there is no number part).

Both are done by adding a ? character after each pattern. We also need to add brackets around the whole number part:

From: (.*?)( \(\d+\))?$
To: \1 [NUM]


Thank you Leo for details explain
CorrectedSequentialNumbers.orp (6.4 KB)

The Solution Doesn't works for me properly.
After I apply This script, This script has been change all of my picture order what I don't want. Let me explain! Look at the screenshot

The Apple series has total 11 files. But Look the Sequential number (Right side of the file name) is reached in 21. The Last file name is Apple (21). That is wrong. I want to correction the Sequential Number series. So The file name should be Apple (1) to Apple (11). Because there is total 11 file in Apple Series. I hope I make you understand. Now I apply the script and Look at the result in my 2nd Screenshot:

The script has been corrected The file name in Apple (1) to Apple (11). But It has been destroyed the Position order of the Picture. I means in the 1st screen shot the picture name Apple (1) in the 1st position and the next picture Apple (2) in the 2nd position, They should be still on that position just should the sequential number corrected. But Look in my 2nd Screen shot The Apple (1) position has changed in to the 6 position, the Apple (2) position has changed in the 1st position and so on for every picture Position has been changed what I don't want. I want Every Picture should be still on their old Position and the Sequential number should be changed as their position number as I Mark out in my 2nd Screenshot.

Almost all (if not every single one) regexp implementations, including the one DOpus/JScript uses, recognizes following special chars:

  • \d: numbers, i.e. [0-9].
  • \D: any non-number, i.e. [^0-9].
  • \w: any "word" character. What "word" means depends on the Regexp implementation, but it usually is [A-Za-z0-9_], meaning most punctuation marks and alike are excluded. In the case of DOpus \w also matches any non-ASCII letters (I use a couple myself), presumably also Bangla. Try replacing [a-z] with \w.
  • \W: any "non-word" character, the negation of above.
  • \s: any space-like chars, incl. a few obscure ones like non-breaking space.
  • \S: any non-space char. By definition \S includes \d, \w, etc. as well. In fact [\s\S] is a very popular pattern to match any chars, including newlines, etc. when /s modifier (dot matches newline) is not readily available.

I don't Think I have any regexp issue here.
From: (.*?)( \(\d+\))?$
To: \1 [NUM]
nicely works. but the position order has been changed what I don't want.

It was meant as a reply to this sentence.

1 Like

oh thanks for that. do you have any idea how to fix the picture position order?

In fact, I do... but not using DOpus. I have a PHP script which does a similar thing, well actually a lot more... I don't have the time to adjust it right now, but if you want to give it a go, send me a message.

If you want to preserve the existing order of things, you might need to rename all the files to something else (e.g. add a prefix which you remove later as a second step) so that any files that are already using some of the numbers in the sequence don't get in the way. The script won't use a number for one file if some other file with the same name and number is already using that number (even if that file is one of the ones you're renaming).

I would do something very similar to Leo's suggestion and do it in 2 steps as well: First add (1) to all files which have no numbers, ie. Orange.jpg -> Orange (1).jpg and then used the script above (which I haven't checked out). Once they're named all by the same pattern, pattern matching is much, much easier, instead of trying to fix 2 things at once and complicating the logic.

Shouldn't it be enough to feed the files in the right order to the script?

1 Like

Looking at it more, the problem happens when a file wants to use the number it is already using. Since the name already exists, it skips its own number and finds the next number no other file is using yet.

The script could be changed to handle that. But adding a prefix that is removed later on is just as easy, I think.

Hi Leo! Finally I am happy because I can make you understood my problem to you. You suggest me to add some prefix that is removed later, Can give me some example in details about that. already 2K Plus of my Picture files Position order just destroyed, :sob: :sob: now I have no choice to fix these 2K Plus files manually. :fearful: If you can fix the script then plz do that, because I have more 13K Plus files to Rename.