Restart numbering for each new set of files

Advanced Renamer forum
#1 : 02/07-18 13:57
Jesse Lewis
Jesse Lewis
Posts: 5
I have a set of files that are currently:

Fileset1_01_UniqueDescript
Fileset1_03_moreUniqueDescript
Fileset2_01_yetanother
Fileset2_01_againmore
Fileset2_04_moreUniquenames
Fileset2_05_stillunique
Fileset3_02_uniqueyet
Fileset3_04_Alwaysspecial
Fileset3_05_verypretty

that should look like this:
Fileset1_01_UniqueDescript
Fileset1_02_moreUniqueDescript
Fileset2_01_yetanother
Fileset2_02_againmore
Fileset2_03_moreUniquenames
Fileset2_04_stillunique
Fileset3_01_uniqueyet
Fileset3_02_Alwaysspecial
Fileset3_03_verypretty

Is there a way to accomplish this? The file names up to the unique descriptor are all the same length, and the numbers occur in the same positions for each.

Also for each file set there is sometimes Fileset1_00, which should be excluded altogether from the list - I assume that will be easy for me to figure out, but I have not yet.

There are 720 file sets and 2-10 files per set.

THANK YOU!


02/07-18 13:57
#2 : 05/07-18 05:15
Jesse Lewis
Jesse Lewis
Posts: 5
Reply to #1:
Hello, I'm hoping someone out there might have a solution to this problem... I am still looking for a way to accomplish this.

THANK YOU!!! You will be my saving grace!


05/07-18 05:15
#3 : 05/07-18 11:41
Domi
Domi
Posts: 25
Reply to #1:
I think you have to write a javascript for this.
My try: http://fs5.directupload.net/images/user/180705/ wisi8g5j.jpg

Add Script method.
-----------------------------------------------------------------------------------
Click "Pre batch script..."-button, and paste:
<code>
var lastFileset = 0;
var i = 0;
</code>
-----------------------------------------------------------------------------------
Click "Show in window..."-button, and paste:
<code>
var fName = item.newBasename;
// RegExp to split filename
var re = /(.+)([0-9]+)_[0-9]+_(.+)/;

var matches = re.exec(fName);
if ( lastFileset != matches[2] ) {
i = 1;
lastFileset = matches[2];
} else {
i++;
}

// fill with leading zeros
var c = ""+i;
while ( c.length < 2 ) c = "0" + c;

var newName = matches[1] +
matches[2] + "_" +
c + "_" +
matches[3];

return newName;
</code>
-----------------------------------------------------------------------------------
Result see screenshot. :)

----------

In special cases you may contact me on Discord: http://bit.ly/dsDisco


05/07-18 11:41
#4 : 05/07-18 16:36
Jesse Lewis
Jesse Lewis
Posts: 5
Reply to #3:
This is amazing - It doesn't work yet on my files, maybe the file unique file length.

Also, my results read: line0: _itemFunc is not defined

td####nn: where td#### is the base name and nn needs to be re-sequenced.

I'm so grateful!!! Sorry I don't speak Java... :/

Jesse


05/07-18 16:36 - edited 05/07-18 16:39
#5 : 05/07-18 19:31
joci
joci
Posts: 10
Reply to #3:
REMOVE THE WORDS <code> and </code> then it works


05/07-18 19:31
#6 : 05/07-18 20:32
Domi
Domi
Posts: 25
Reply to #5:
Yes, joci is right. Don't copy the <code></code> tags. :)
If it still doesn't work, pls give more filenames.

----------

In special cases you may contact me on Discord: http://bit.ly/dsDisco


05/07-18 20:32
#7 : 05/07-18 21:41
Jesse Lewis
Jesse Lewis
Posts: 5
Reply to #6:
I'm sorry I'm still having trouble. - no <code></code> tags in there anymore. I get line 7: match is null

Here is a sample set of files: https://www.dropbox.com/s/b85fxb6bktxfso5/temp.z ip?dl=0

I would like to also ignore any file with "00_" if possible...

THANK YOU SO MUCH!


05/07-18 21:41
#8 : 05/07-18 23:20
Domi
Domi
Posts: 25
Reply to #7:
Of course my script does not work. Becouse the file do not look like you posted the samples.
Your sample filenames had 2 _ in it. Those in your temp.zip only have 1 _.

Also, I don't see any files with "00_". If you want to use automatic renaming you must be as precise as possible.

The files from the zip can be renamed with a simple replace method. But you must tell us what you want to have as result! Exacly. I don't know what those numbers mean.

Quick replaceing: http://fs1.directupload.net/images/user/180705/ ydjktusv.jpg


----------

In special cases you may contact me on Discord: http://bit.ly/dsDisco


05/07-18 23:20
#9 : 06/07-18 03:05
Jesse Lewis
Jesse Lewis
Posts: 5
Reply to #8:
Thanks for the explanation... I'm sorry this became such a hassle.

Old Names: https://www.dropbox.com/s/jojz61wdfu37h1e/OldNam es.JPG?dl=0
New Names: https://www.dropbox.com/s/hegirodz8x6mfql/NewNam es.JPG?dl=0

These file names are set to be read by a program, and represent a set of sound files. Each button executes a sound file chosen at random from its set.

tdpprc##_uniquedescriptor
- td is just how we start the file
- pp is the two digit page
- r is the row
- c is the column
- ## is the two-digit number I'm trying to fix. It's chosen by a random number generator, so there cannot be repeats or holes in the sequence.
- _uniquedescriptor so that it's human readable

I'll be so glad if that makes sense, and hopefully the extra information is more helpful than not. I feel horrible that I haven't been able to explain it well... I feel like your script was perfect from your screen shot - I'm sorry I've had trouble implementing!

Thank you! and I hope you are still willing to help...
Jesse L


06/07-18 03:05 - edited 06/07-18 03:13
#10 : 06/07-18 09:03
Domi
Domi
Posts: 25
Reply to #9:
Gooooooood Morning! Now I can see the light. :-)

Please note, this script will only work if your filenames look exacly like described. Any unexpected additional character may destroy the regular expression that splits the name into parts.

Here are the new scripts. Changes in both !!! So replace both! And don't copy the ---------------------lines. :-)

"Pre batch script":
---------------------START copying below this line:
var lastFileset = "";
var i = 0;
---------------------STOP copying above this line.

"Show in window...":
---------------------START copying below this line:
var fName = item.newBasename;
// RegExp to split the filename:
// match: 1td 2pprc ## 3text
var re = /(.{2})([0-9]{4}).+_(.+)/;
var matches = re.exec(fName);

if (lastFileset != matches[2]) {
i = 1;
lastFileset = matches[2];
} else i++;

// fill with leading zeros
var c = "" + i; while (c.length < 2) c = "0" + c;

var newName = matches[1] +
matches[2] +
c + "_" +
matches[3];

return newName;
---------------------STOP copying above this line.

I hope it will work for all your files. Have a nice day.

----------

In special cases you may contact me on Discord: http://bit.ly/dsDisco


06/07-18 09:03
#11 : 06/07-18 09:21
Domi
Domi
Posts: 25
--------------------------------------------------------------
Supplement for the AR-Devs:
--------------------------------------------------------------
In the example files was 1 file that differed a little bit. Therefor my RegExp did not work for it, and I got only 2 matches, instead of the expected 3.
AR marked ALL files in the list with the error. That made it hard to find the file/error. Becouse the first 50 files worked fine.
Maybe it is possible to change this, and start showing ERROR on the line that fired the error, and not on all lines.
THX

----------

In special cases you may contact me on Discord: http://bit.ly/dsDisco


06/07-18 09:21