NOOB asking for script help with two rename problems

Any questions? Need some help?
Post Reply
Kallita
Posts: 4
Joined: 29 Dec 2019, 20:55

NOOB asking for script help with two rename problems

Post by Kallita »

Thanks for any help provided.
I am a relative noob to programming but have been able to cobble together several scripts for the gui that run with relative correctness, but am having problems with 2 situations :
the first: I have a script to modify a file name but have some files that end with "(1)" "(2)" (3) etc [without the quotes] that usually indicate duplicates, and I can't figure out how to remove those brackets and number and not remove other brackets and contents. It is not on all files only those that are duplicate.
Second: I have a bunch of words (10 right now, but could add more) that I remove from the file name. Right now I am just using fn.removeAll("words") for each instance/word that i want to remove. some of the words start with a - and others do not. for example removeAll("-worda").removeAll("wordb").removeAll("word-c") . although this works I can't help thinking it is inefficient and was wondering if there was a way of doing it more succinctly that would allow for the future addition of more words.
thanks for your time and a great program
Kallita
User avatar
rednoah
The Source
Posts: 18826
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: NOOB asking for script help with two rename problems

Post by rednoah »

1.
FileBot has a helper function for that one:

Code: Select all

"Test (1)".replaceTrailingBrackets() # Test

2.
/regular expressions/ allow you to describe generic text patterns succinctly: https://regexr.com/

Code: Select all

"A B C 1 2 3 4 5".removeAll(/B|C|[0-9]+/) # A
:idea: Please read the FAQ and How to Request Help.
Kallita
Posts: 4
Joined: 29 Dec 2019, 20:55

Re: NOOB asking for script help with two rename problems

Post by Kallita »

Thanks for the help!
I am using filebot on a windows 10 (if that matters) in plain file rename mode

here is an example of the file names i am running through filebot:
All Star Western 097 (1957) (c2c) (Superscan)
2000AD 2164 (2020) (Digital-Empire)(1)

here is the code I am using pretty simple

Code: Select all

d:\comics alphabetical/{n[0]}/{fn.removeIllegalCharacters().replaceAll(/[!?.]+$/).replaceAll(/[`´‘’ʻ_,.]/, " ").replaceFirst(' 0', '_0').replaceFirst(' 1', '_1').replaceFirst(' 2', '_2').replaceFirst(' 3', '_3').replaceFirst(' 4', '_4').replaceFirst(' 5', '_5').replaceFirst(' 6', '_6').replaceFirst(' 7', '_7').replaceFirst(' 8', '_8').replaceFirst(' 9', '_9').replaceFirst('_', "/")}
When using replaceTrailingBrackets() in this code it will remove the (1) <which is what I want >But it will also remove the (Superscan) from the first one<which I don't want>
I went to the regexr site that you had tagged in your reply and came up with a removeAll(\(1\)|\(2\)) that seemed to work on finding the characters but when I attempted to add it to the filebot script it gives me an unexpected \ error and won't save.
as I said I am a noob for programming so I am thinking I am just missing something. So any help is appreciated.
ps : not sure how to get the code box to pop up.... sorry
kallita
kim
Power User
Posts: 1018
Joined: 15 May 2014, 16:17

Re: NOOB asking for script help with two rename problems

Post by kim »

Code: Select all

.replaceFirst(' 0', '_0').replaceFirst(' 1', '_1').replaceFirst(' 2', '_2').replaceFirst(' 3', '_3').replaceFirst(' 4', '_4').replaceFirst(' 5', '_5').replaceFirst(' 6', '_6').replaceFirst(' 7', '_7').replaceFirst(' 8', '_8').replaceFirst(' 9', '_9')
=

Code: Select all

.replaceFirst(/\s(\d)/, '_$1')
remove e.g. (1) only at the end

Code: Select all

.replaceAll(/\(\d\)$/)
Kallita
Posts: 4
Joined: 29 Dec 2019, 20:55

Re: NOOB asking for script help with two rename problems

Post by Kallita »

Thanks very much for the help Kim.
Both seem to be working perfectly.
I will continue to play with these and the whole program and hopefully learn more about the regex system.
Kallita
User avatar
rednoah
The Source
Posts: 18826
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: NOOB asking for script help with two rename problems

Post by rednoah »

This might be too technical, but here's the official docs on slash strings:
https://docs.groovy-lang.org/latest/htm ... shy_string
:idea: Please read the FAQ and How to Request Help.
Kallita
Posts: 4
Joined: 29 Dec 2019, 20:55

Re: NOOB asking for script help with two rename problems

Post by Kallita »

thanks for the Groovy page. I will be going through it over the next little while.
kallita
Post Reply