Repeat a number file name in specific cases

Advanced Renamer forum
#1 : 21/07-20 23:10
Sergio Ocampo
Sergio Ocampo
Posts: 4
Hello all! I have a huge list of photographs I need to rename, and I have found the following problem:

The original files are named like this:

name001.tif
name002.tif
name003.tif
name003_2.tif
name004.tif
...and so on.

the "_2" at the end of the "003" file, means that this photo is the back part of the original photo (003).
So, I need the app to repeat the previous filename only in the cases where a "_2" is present at the end of the name, and then continue with the natural order. Is this possible? I've been trying to do it all day with no results.

I hope this made sense!

Thanks in advance



21/07-20 23:10
#2 : 22/07-20 12:53
David Lee
David Lee
Posts: 1125
You will need to use a script for this.

Check out the User Guide for help converting your replace methods into a script.

Then create a Script method and create a string variable "lastname" in the Pre batch scrip and set it to null:

var lastname = "";

Then in the main script :

if (item.name.slice(-2)=="_2"){
newname = lastname + "_2";
} else {
newname = <insert code to rename current file>;
lastname = newname;
}
return newname;


22/07-20 12:53
#3 : 22/07-20 20:30
Sergio Ocampo
Sergio Ocampo
Posts: 4
Reply to #2:

Thank you David for your help! That is super useful. However, I have absolutely no background on JS, so I didn't really understand how to convert the replace methods into a script. I need to accomplish this and this app is the best I could find to do this. Would it be possible that you or any other more experienced user can help me with this? I've already gone through different entries on the forum but to no avail.

So, in short, I need to know, how can I, using js language, delete all the file name, and then construct the new filename with "FP_" + (7 digit number starting with pre-fixed number).

The following part, which would be the script David wrote, is already covered.

Would this be it? Did I understand correctly?

I really hope someone can help me with this.

Thanks in advance.

Best Regards, Sergio


22/07-20 20:30
#4 : 23/07-20 02:17
David Lee
David Lee
Posts: 1125
Reply to #3:
It will be straightforward. However I have absolutely no idea what you mean by "7 digit number starting with pre-fixed number". Please give examples.


23/07-20 02:17
#5 : 23/07-20 17:23
Sergio Ocampo
Sergio Ocampo
Posts: 4
Reply to #4:

Hello David thank you so much for replying.
I'll try to explain it with a little more detail this time.

I have to rename a huge quantity of photos, which are separated in many different folders. Depending on the folder, the files will need to be renamed with a distinct code and a 7 digit number, following this structure:

FP_0000000

In this case, FP is the code and I need to be able to change it depending on the folder. Sometimes it will be N35, FPC, NG, etc.

The number needs to be a 7 digit number, and I also need to be able to type in whatever number the count will start depending on the folder, so for example It'll sometimes start with 0000049 and others with 0003489, etc.

Until this part, I have no trouble renaming it with the options the software gives me.
However, there are some pictures that have a front and a back part, which are the ones that I talked about in my first post. In these cases is where I need the program to recognize the "_2" at the end of the filename and repeat the previous file name plus a "_01" instead of "_2".
For example:

PAILLACO006 > FP_0000060
PAILLACO006_2 > FP_0000060_01

The steps I followed using the program until I came across this problem were just two:

1.Remove
Remove count: whatever number of characters are in the name before the "_2"
Starting at: 1

2.Add
Add:FP_<Inc Nr:0000952>
At Index:0

Also, the original names vary in the number of characters they have.
For example, some folders will have files named "czischke001+.tif", and others "grob001+.tif". So I don't know if when using a script I would need to type in how many characters I need removed (like the "Remove" method) or what.

I really hope I made any sense! English is not my mother tongue. I hope this is doable.
I really appreciate your help, many many thanks.



23/07-20 17:23
#6 : 24/07-20 10:57
David Lee
David Lee
Posts: 1125
Reply to #5:
I'm still not completely sure that I understand you.

However try this script method...

Pre batch script:

prefix = "FP"
number = 3489;
var lastname="";

Main script:

if (item.name.slice(-2)=="_2"){
newname = lastname + "_2";
} else {
newname = prefix+(("0000000" + number).slice(-7));
number++;
lastname = newname;
}
return newname;

Change the prefix and starting number in the pre batch script as appropriate.



24/07-20 10:57
#7 : 24/07-20 18:22
Sergio Ocampo
Sergio Ocampo
Posts: 4
Reply to #6:

Hello David! Thank you so so much! This was exactly what I needed and it worked perfectly!!


24/07-20 18:22