Examples: Custom Rename Keys (Opus 13)

When renaming files, you can make custom actions to highlight or modify parts of the filename.

There are several examples built into the program.

Some very simple, like Ctrl+A (select all), which just does a regexp match on (.*):

And some are quite complex, like Ctrl + [ and Ctrl + ] which take filenames like:

One Two - Three Four - Five - Six - Seven Eight.txt

and move the part under the cursor around, like so:

You can see how each is implemented within the program.

Here's an example that isn't built-in.

It takes a filename like this:

[Unwanted stuff] Wanted stuff in the middle (More unwanted stuff).txt

And:

  • Removes anything at the start or end in [...] or (...)
  • Places the cursor at the end of the new name, before the extension

Code:

newstem = Trim(RegEx(valstem,
	"^[\[\(][^\[\(\]\)]+[\]\)](.+)$", "\1",
	"^(.+)[\[\(][^\[\(\]\)]+[\]\)]$", "\1"));
selstart = Len(newstem);
selend = selstart;
return newstem + valext;
  • valstem is the filename without extension.
  • valext is the extension.
  • newstem is my own variable
  • RegEx applies one or more regex find & replace operations. (Applies two in this case.)
  • selstart and selend are both input and output. They tell you where the cursor was and what was selected, and you can modify them to change those things too.

These things can also be shared in XML form, which lets you import all the settings (not just the code) at once. Here it is, if you want to play with it:

<?xml version="1.0"?>
<regexsel key="219,3" name="Delete text in brackets from start and end, put cursor at end">
	<eval>newstem = Trim(RegEx(valstem,
	&quot;^[\[\(][^\[\(\]\)]+[\]\)](.+)$&quot;, &quot;\1&quot;,
	&quot;^(.+)[\[\(][^\[\(\]\)]+[\]\)]$&quot;, &quot;\1&quot;));
selstart = Len(newstem);
selend = selstart;
return newstem + valext;</eval>
</regexsel>

I like this, and had a quick play.

Can you add the ability to UNBIND a hotkey without needing to delete it?

Also, is there a way to select JScript instead of VBScript in the Evaluator Clause?

Cheers.

It's neither:

The grammar of the evaluator is similar to that of JScript (Javascript) and C++.

Evaluator Grammar