Here me out !

Advanced Renamer forum
#1 : 21/01-22 00:33
Shaun
Shaun
Posts: 7
i have a list of entries that i want to remove from the filename and have been using the "remove pattern" function as of now with name1 \ name 2\ etc with the \ as the separator.
This list is getting very long now

so i was wondering if the import function would be something to use instead like a CSV database, so i could update that and Advance Renamer would take it from there ?


21/01-22 00:33
#2 : 21/01-22 13:54
David Lee
David Lee
Posts: 1125
Advanced Renamer can read lines or characters from a file using the <File Line> and <File Content> tags.

Note that <File Line> is not included in the User Guide but you can find a description on the "What's new" page under Version 3.61 (https://www.advancedrenamer.com/whatsnew)

It will be most convenient if you save your list of patterns to a text file with one pattern per line.

Using a Script method, read the patterns into an array, one line at a time, using the <File Line>tag in the Pre batch script. Then, in the main script, replace each pattern with a null string.

ie...

Pre batch script:

file = "C:\\folderpath\\patterns.txt";
patterns = [];
n=1;
while (line = app.parseTags('<File Line:' + n + '::"' + file + '">')) {
patterns[n] = line;
n++;
}

Main script:

name = item.newBasename;
for (j=1; j<n; j++) {
name = name.replace(patterns[j], '');
}
return name;

In the Pre batch script replace "file = "C:\\folderpath\\patterns.txt";" with the full path and filename of your text file. Note that you must replace each "\" in the Windows path with "\\".

This script will remove only the first occurrence of each pattern in each filename. To remove multiple instances you will need to save the patterns as Regular Expressions with the global flag ("g")

ie Pre batch script:

file = "C:\\folderpath\\patterns.txt";
patterns = [];
n=1;
while (line = app.parseTags('<File Line:' + n + '::"' + file + '">')) {
patterns[n] = RegExp(line, 'g');
n++;
}

The main script stays the same.


21/01-22 13:54 - edited 21/01-22 14:02