Text file with replacements for Bulk Rename to use

Post any Bulk Rename Utility support requirements here. Open to all registered users.

Text file with replacements for Bulk Rename to use

Postby damienm » Tue Sep 20, 2022 11:00 am

I have many files with various strings I would like to replace and I noticed some of the strings repeat on some files. Is it possible to create a text file with all the possible strings that Bulk Rename Utility will read and apply to all the selected file (e.g. across entire directory).

For example imagine a directory with many files similar to the ones below:
file1.ABX.xyz.doc
file2.abs.efg.doc
file3.version1.abx.xyz.doc
file3.abc.efg.doc
file4.v45.abs.efg.doc
file5.abc.efg.3546.doc
file7.abc.efg.3546.doc

Can I create a text file with a new line for each replacement and have Bulk Rename use the file and apply all the changes across the directory?
File contents might be:
.abx.xyz
.abs.efg
.abc.efg
.ABC.efg.3546

So the resulting files would be:
file1.doc
file2.doc
file3.version1.doc
file3.doc
file4.v45.doc
file5.doc
file7.doc
damienm
 
Posts: 3
Joined: Tue Sep 20, 2022 10:42 am

Save replacements

Postby Luuk » Tue Sep 20, 2022 3:20 pm

To delete those text-strings, you could first make a text-file like...
.,a,b,X,.,x,y,z=
.,a,b,s,.,e,f,g=
.,a,b,c,.,e,f,g=
.,A,B,C,.,e,f,g,.,3,5,4,6=

Or if always at the end of .doc files, would need a checkmark inside of "Renaming Options, File/Folder extensions, Rename File extensions".
Then the file would have to look more like...
.,a,b,X,.,x,y,z,.,d,o,c=.,d,o,c
.,a,b,s,.,e,f,g,.,d,o,c=.,d,o,c
.,a,b,c,.,e,f,g,.,d,o,c=.,d,o,c
.,A,B,C,.,e,f,g,.,3,5,4,6,.,d,o,c=.,d,o,c
Then to paste these contents after using "Special, Character Translations", but these characters will always be case-sensitive!
To save all of your replacements for future renames, can just use the menu "File, Save As" to invent a settings-file.

Another way could be using the Replace(3) with a Replace like... .abx.xyz|.abs.efg|.abc.efg|.ABC.efg.3546.
If the characters are always at the end of names, its like... \end\.abx.xyz|.abs.efg|.abc.efg|.ABC.efg.3546.
The Replace(3) characters will not be case-sensitive, unless putting a checkmark inside for "Match Case".

Another way with RegEx(1) having a checkmark inside for "v2" is a Match like... (?i)\.(abx\.xyz|ab[cs]\.efg(\.3546)?)$.
The (?i) says "case-insensitive", and the $ says "at the end", but I would need more samples to improve this match.
It really doesnt matter which method, just whatever is easiest, but then save everything into a settings-file.
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm

Re: Text file with replacements for Bulk Rename to use

Postby damienm » Thu Sep 22, 2022 11:29 am

I tried Replace(3) option and it worked well, however I actually have about 400+ replacements and the string gets too long to manage in Replace(3).

Will have a go at the first two options to see if I can get them to work, just means a lot of editing a very large list of replacements with .,a,b,X,.,x,y,z= format.

Thanks for the info. :D
damienm
 
Posts: 3
Joined: Tue Sep 20, 2022 10:42 am

Save replacements

Postby Luuk » Thu Sep 22, 2022 3:29 pm

If you did already have a list of removals looking like...
.abx.xyz=
.abs.efg=
.abc.efg=

The free notepad++.exe could insert your commas, using the menu "Search, Replace" with a checkmark inside for "regular expression".
So then you could just click "Replace All", after using a "Find what" like... ([^=\r\n])(?!=)(?!$) and a "Replace with" like... \1,
If the list does not yet have '=' at the ends, then first use (?<!=)$ with = to add '=' to any lines that dont already end with '='.
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm

Re: Text file with replacements for Bulk Rename to use

Postby damienm » Fri Sep 23, 2022 12:02 am

Thanks Luke will give that a try.

Once the text file is ready, how do you actually use it with Bulk Rename Utility? Is it the same principle as Import Rename-Pairs? I tried the Import Rename-Pairs based on the format .,a,b,X,.,x,y,z= and it doesn't seem to work so I think I have the basic principle wrong.
damienm
 
Posts: 3
Joined: Tue Sep 20, 2022 10:42 am

Save replacements

Postby Luuk » Fri Sep 23, 2022 8:33 am

Once the text-file is ready, can just use the menu... "Special, Character Translations".
Then to paste your whole file-contents into this window, for testing all of your removals.
Whem its finished, then "File, Save As" can save everything into a .bru settings-file for later.

For myself, I do just keep 1-file without any commas or equals, and just let the notepad++ convert it for my copy/pasting.
This because my notepad++ has a macro called BRU-Char-Trans, to auto-convert them, making it very easy to copy/paste.
The Rename-Pairs uses another format like Original-Name.doc|New-Name.doc, so its always wanting the whole filenames.


If you like to invent a similiar macro for notepad++, can use 2-regexs in this order...
^([^=\r\n]+)$
\1=
This to put '=' at the very end, when theres not any '=' somewhere on the line already.

([^=,\r\n])(?!([=,]|$))
\1,
This to put commas anywhere that might be needed.


So if you have an incomplete file, the whole macro will convert your lines like...
.abx.xyz ----------> .,a,b,x,.,x,y,z=
.abs.efg ----------> .,a,b,s,.,e,f,g=
.abc.efg ----------> .,a,b,c,.,e,f,g=
Rem,ove1 --------> R,e,m,o,v,e,1=
R,emove2 --------> R,e,m,o,v,e,2=
Remove,3= -------> R,e,m,o,v,e,3=
dogs=canines ----> d,o,g,s=c,a,n,i,n,e,s
c,ats=felines -----> c,a,t,s=f,e,l,i,n,e,s
Replace1=With1 -> R,e,p,l,a,c,e,1=W,i,t,h,1

So lines without '=' will be converted into removals by adding '=' to the end, and then it just comma-separates the rest.
To create this macro, can use "Macro, Start Recording", then type the 1st Find and Replace, and then click "Replace All".
Then just type the 2nd Find and Replace, and click "Replace All" again, and then use "Macro, Stop Recording".
This will let you save it with "Macro, Save Current Recorded Macro" and just give it any descriptive name.

The main things to remember about Char Translations, is that he is always case-sensitive, so you must include all possible matches!
And also should probably never use very short text-strings, because those text-strings might also be found inside of other words.
So like if you were using the above Char Translations, it would convert catsup ---> felinesup.

So very short-strings are safer inside of RegEx(1) with negative look-arounds, and use Character Translations for the rest.
Both of them will always be saved inside of your .bru settings-file anyways, when using the menu "File, Save As".
If needing help to convert anything for RegEx(1), can just post some examples and I will try.

If needing to replace any commas or '=', they first have to be converted into 2c or 3d before comma-separating.
So I would just put those replacements into either Replace(3) or RegEx(1), so then not having to edit the macro.
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm


Return to BRU Support


cron