Random Renumbering

Advanced Renamer forum
#1 : 25/11-19 13:44
Mike
Mike
Posts: 1
hi all

I am looking to rename audio files with a random number so when I use a thumb drive in may car the songs are not played in alphabetical order - any suggestions?

Cheers
Mike


25/11-19 13:44
#2 : 25/11-19 19:16
Styb
Styb
Posts: 7
Reply to #1:
Try the Random tag (open the New name method and select Advanced tag).


25/11-19 19:16
#3 : 26/11-19 04:04
dris2
dris2
Posts: 1
The road of love was only by himself so he had to step If love is only on the lips, I do not need you to say Hey dear, I still remember or have forgotten The places I vowed and the places I used to go We used to experience and taste the night together So how is the moon with the sun? How you, how you, how you
<a href="https://krunker-io.co
<a href="https://super-smashflash2.com


26/11-19 04:04 - edited 26/11-19 04:05
#4 : 28/11-19 22:46
Alex Foster
Alex Foster
Posts: 11


28/11-19 22:46
#5 : 29/11-19 16:23
David Lee
David Lee
Posts: 292
Reply to #4:

You can do this more simply using a single Pre batch script.

Open a Script method.
Leave the Script window blank.
Click the "Pre batch script..." button
Enter the code below.
Click "Close and apply script".
Then "Start batch"

Pre batch script:

var nmax = app.itemCount;
var test = [0];
for (n = 0; n < nmax; n++) {
test[n] = 0;
}
n = 0;
for (n = 0; n < nmax; n++){
do {
x = Math.floor(Math.random() * nmax);
}
while (test[x] == 1);
test[x] = 1;
app.getItem(n).newName = x + 1;
}


This will rename all your files with a non-repeating number between 1 and the total number of files.

If you would like all your filenames to be the same length then, for two digits (ie padded with up to one leading zero), replace the last line of the script with:

app.getItem(n).newName = ("0" + (x + 1)).slice(-2);

for three digits with:

app.getItem(n).newName = ("00" + (x + 1)).slice(-3);

etc etc


Finally, if you want to keep the original filenames and prefix them with a random number then:

var nmax = app.itemCount;
var test = [0];
for (n = 0; n < nmax; n++) {
test[n] = 0;
}
n = 0;
for (n = 0; n < nmax; n++){
do {
x = Math.floor(Math.random() * nmax);
}
while (test[x] == 1);
test[x] = 1;
itm = app.getItem(n)
itm.newName = ("00" + (x + 1)).slice(-3) + "-" + itm.newName;
}

If you use this final version of the script then you can easily re-randomize the files to change the order by running the same Script method but preceding it with a Remove pattern method to get rid of the previous random prefixes...

Pattern: ^\d*-
Use regular expressions: √


29/11-19 16:23 - edited 29/11-19 16:44