Change two files

Advanced Renamer forum
#1 : 27/11-17 08:51
Ulf Andersson
Ulf Andersson
Posts: 3
Hello!

When i have my list of files, for example dsc_001, dsc_002, dcs_003, dsc_004, dsc_005, dsc_006 i would like to make it organize the files 2 and 2. So dsc_001 and dsc_002 become a copy of eachother. So new name on my files dsc_001, dsc_002, would be dsc_001 (1) and dsc_001 (2), and so on, so instead of renaming one i want to rename 2 to the same name, and the list of files is approximately 1500 files. Is this possible?


27/11-17 08:51
#2 : 27/11-17 09:24
Stefan
Stefan
Posts: 274
Reply to #1:

>>So dsc_001 and dsc_002 become a copy of eachother.

You don't mean a real file copy, to make the same file content, don't you?
You just want to rename the file names, right?

- - -

FROM:
dsc_001.ext
dsc_002.ext
dcs_003.ext
dsc_004.ext
dsc_005.ext
dsc_006.ext

TO:
dsc_001 (1).ext
dsc_001 (2).ext ---was dsc_002
dcs_002 (1).ext ---was dsc_003
dsc_002 (2).ext ---was dsc_004
dsc_003 (1).ext ---was dsc_005
dsc_003 (2).ext ---was dsc_006

.


? ? ? ? ?
 


27/11-17 09:24 - edited 27/11-17 15:02
#3 : 27/11-17 13:25
Ulf Andersson
Ulf Andersson
Posts: 3
Reply to #2:

Yes exactly. Sorry if I made it complicated.


27/11-17 13:25
#4 : 28/11-17 10:13
Stefan
Stefan
Posts: 274
Reply to #3:

***
EDIT:
there is a bug if my 'idx' becomes '10' and then again at '20'...

I will try to find time to provide an update.
***

Are you sure you have no gaps in your current numbering?
Not smtg like: 1, 2, 5, 6, 7, 12, 13?
But straight 1,2,3,4,5,6,7,8,9..... with no missing numbers.


Then you can use this JavaScript.
Attention, there is no errorhandling, if your current names
are not in order this renaming will mess it up (have a backup!)


FROM:
dsc_001.ext
dsc_002.ext
dsc_003.ext
dsc_004.ext
dsc_005.ext
dsc_006.ext
dsc_065.ext
dsc_066.ext
dsc_111.ext
dsc_112.ext

TO:
dsc_001 to dsc_001 (1).ext
dsc_002 to dsc_001 (2).ext
dsc_003 to dsc_002 (1).ext
dsc_004 to dsc_002 (2).ext
dsc_005 to dsc_003 (1).ext
dsc_006 to dsc_003 (2).ext
dsc_065 to dsc_004 (1).ext
dsc_066 to dsc_004 (2).ext
dsc_111 to dsc_005 (1).ext
dsc_112 to dsc_005 (2).ext


USE this Script for the first PREVIEW:
------------------------------------------
if(index==0){idx=index +1};
digits = parseInt(item.name.slice(-3));
if(digits %2 == 0){
ser = ' (' + 2 + ')'; num=idx; idx++;
}else{
ser = ' (' + 1 + ')'; num=idx;
}
num = ('0000'+num).slice(-3);
return item.newBasename+' to '+ 'dsc_'+ num + ser;
------------------------------------------


.
.

# # #

If the names looks good in the preview, remove the "item.newBasename+' to '+" part:

TO get:
dsc_001 (1).ext
dsc_001 (2).ext
dsc_002 (1).ext
dsc_002 (2).ext
dsc_003 (1).ext
dsc_003 (2).ext
dsc_004 (1).ext
dsc_004 (2).ext
dsc_005 (1).ext
dsc_005 (2).ext

------------------------------------------
if(index==0){idx=index +1};
digits = parseInt(item.name.slice(-3));
if(digits %2 == 0){
ser = ' (' + 2 + ')'; num=idx; idx++;
}else{
ser = ' (' + 1 + ')'; num=idx;
}
num = ('0000'+num).slice(-3);
return 'dsc_'+ num + ser;
------------------------------------------




# # #

HTH?


index = is the current file index, provide from ARen
digits = are the last three signs of the original name, the three digits
idx = is my own file index
num = is the new numbering for the file name, based on my idx
ser = is the serialization (1) / (2)


I' am sure a good scripter is able to clean and improve my code. But it should work as it is now too.


28/11-17 10:13 - edited 28/11-17 16:17
#5 : 28/11-17 17:45
Ulf Andersson
Ulf Andersson
Posts: 3
Reply to #4:
Perfect thank you very much! This will make my life so muck easier. But another question, If i want to change the files like this but i want the numbers to start on another number than DSC_001. For example:

Dsc_0413 >> 47987(1)
Dsc_0414 >> 47987(2)
Dsc_0415 >> 47988(1)
Dsc_0416 >> 47988(2)
Dsc_0417 >> 47989(1)
Dsc_0418 >> 47989(2)

How do i change this?
So grateful for your help.


28/11-17 17:45
#6 : 28/11-17 20:38
Stefan
Stefan
Posts: 274
Reply to #5:
>>but i want the numbers to start on another number than DSC_001.


Then we would initialize my 'idx' var with '47987'
if(index==0){idx=47987};


And remove the number formatting line:
num = ('0000'+num).slice(-3);

and that 'dsc' string from the new name:
'dsc_'+





Something like this:


------------------------------------------
// START NUMBER:
// if(index==0){idx=index +1};
if(index==0){idx=47987};

// GET LAST THREE SIGNS FROM NAME:
digits = parseInt(item.name.slice(-3));

//IF DIGITS ARE EVEN
if(digits %2 == 0){
ser = ' (' + 2 + ')'; num=idx; idx++;
}else{
//IF DIGITS ARE ODD
ser = ' (' + 1 + ')'; num=idx;
}

// NUMBER PADDING:
//num = ('0000'+num).slice(-3);

// COMPOSE THE NEW NAME:
return num + ser;
------------------------------------------






But first I have to find the bug in my algorithm.


28/11-17 20:38