Remove all brackets and what it contains except

I have been in the process of converting over regex that I use with a file renamer utility called flash renamer. This one I have been using is strung together in multi parts. Flash renamer will let you string together commands and run them together as one batch. I was wondering if you could help convert this for use in opus and if it can be condensed into one button if possible. If not what would be the most streamlined way to accomplish what i need in opus. So that I can retire flash renamer.

Remove Brackets around series info but keep the series info &
Remove all brackets and the info they contain accept version info and its brackets.

Many of the ebooks I have that need to be renamed prior to import have bracketed information sometimes the brackets are square "[ ]", Round "( )" or Other "{ }". The files appear like so.

George Carlin - Your Mama! (funny jokes 123) (v3.2) (mobi).mobi
George Carlin - Your Mama! (reprint) (v1.5).epub
George Carlin - Your Mama! (v5.0) (pdf).pdf
George Carlin - Your Mama! (funny jokes 123) (v3.2) (mobi).mobi
George Carlin - Funny Jokes 1 - Your Mama! (reprint) (v1.5).epub
George Carlin - Funny Jokes 1 - Your Mama! (v5.0) [pdf].pdf
George Carlin - Funny Jokes 1 - Your Mama! (funny jokes 123) (v3.2) (mobi).mobi
George Carlin - Funny Jokes 1 - Your Mama! (reprint) (v1.5).epub
George Carlin - Funny Jokes 1 - Your Mama! (v5.0) (pdf).pdf
George Carlin - [Funny Jokes 1] - Your Mama! (funny jokes 123) (v3.2) (mobi).mobi
George Carlin - Funny Jokes 1 - Your Mama! (reprint) (v1.5).epub
George Carlin - Funny Jokes 1 - Your Mama! (v5.0) [pdf].pdf

  1. The first thing i do is change all brackets to rounded "( )";

  2. This is so I can then remove the brackets from around the series by doing a find and replace of
    Find "- (" replace "- "
    Find ") -" replace " -"
    this gets rid of the brackets but leaves me with series info if there happens to be series.

  3. Change version info brackets to square.

Match: (.+)((v.+?))(.*)
Repla: \1[\2]\3

  1. This is so that a Wild Card Deletion of all rounded brackets and the information they contain can be run (opus doesn't seem to have wildcards)
    find all rounded brackets and what they contain "(*)" replace with nothing ""

  2. Then the square brackets in the version info is returned to rounded "( )"

so the files will turn out to look like this:

George Carlin - Your Mama! (v3.2).mobi
George Carlin - Your Mama! (v1.5).epub
George Carlin - Your Mama! (v5.0).pdf
George Carlin - Your Mama! (v3.2).mobi
George Carlin - Funny Jokes 1 - Your Mama! (v1.5).epub
George Carlin - Funny Jokes 1 - Your Mama! (v5.0).pdf
George Carlin - Funny Jokes 1 - Your Mama! (v3.2).mobi
George Carlin - Funny Jokes 1 - Your Mama! (v1.5).epub

any help with this would be appreciated. Another big question I have is; can commands be strung together as a batch in opus as well?

Here's the script I sent offline to penguinaka. Since there aren't many perlscripts here, I thought I'd share it. I'll explain how it works if anyone is interested (but more fun to figure it out!):

Set the Case sensitive checkbox.

[code]@script perlscript

sub Rename_GetNewName2
{
my ($strFileName, $strFilePath, $fIsFolder, $strOldName, $strNewName) = @;

$strFileName =~ s/\s+[[^]]+](?: -)?//;
$strFileName =~ s/\s?((?:(?!v[\d.]+).)*)//g;

$strFileName = "$strFileName--" . rand() if -e "$strFilePath/$strFileName";

return $strFileName;
}[/code]

One thing to note, I tried using the "Automatically rename if new filename exists", but it seems to not correctly deal with the case where a file ends with something that looks version'ish. Example, "(v5.0)" at the end of a filename becomes "(v5. (1)". Unfortunately, the Preview window doesn't show the interaction when "Autmatically rename..." is enabled.

So, I added code in the script to avoid same-named files and overwrite warnings. But, in such code, it would be nice if dopus passed in an extra parameter, which could be an index of the file being operated on, or some other guaranteed unique number across a rename run, so that scripts could utilize this number to prevent overwrite file warnings by guaranteeing uniqueness.

Anyway, just some observations and thoughts.