Dots to spaces except in numbers. (For files and folders.)

This post presents two ways to achieve this type of rename:

Dots_to_spaces_except_in_numbers_purpose

Dots in the name will be turned into spaces except if they are in between numbers (like in a version number). For files, the dots in their file extensions are left alone.

The post has been updated for Opus 12, while keeping the old Opus 11 methods below.


Part 1 -- Opus 12 and above

This task is much easier with Opus 12, thanks to the option to preserve file extensions while applying wildcards and regular expressions.

The ignore extension option means we can use a single regular expression for both files and folders. It also means we will automatically handle complex extensions like .part1.rar for multi-part RAR files (as long as Opus is aware of them).


Opus 12 & above -- Method One: Toolbar Button

If you only want a toolbar button (or hotkey) you can click to rename the selected items, and you don't want to clutter up the list or rename presets in the Rename dialog, then you should create a button which runs this command:

@NoDeselect
Rename IGNOREEXT REGEXP PATTERN="(.*)(([^0-9])\.|\.([^0-9]))(.*)#" TO="\1\3 \4\5" 

(This button uses a rather complex regular expression. If you are new to regular expressions see this post for some much simpler examples: RegExp basics: Removing characters from start/end of names.)

Here is the same button in XML format so you can paste it to your toolbar:

(See: How to add buttons from this forum to your toolbars)

<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>Dots to Spaces</label>
	<tip>Rename dots to spaces, except in numbers</tip>
	<icon1>#rename</icon1>
	<function type="normal">
		<instruction>Rename IGNOREEXT REGEXP PATTERN=&quot;(.*)(([^0-9])\.|\.([^0-9]))(.*)#&quot; TO=&quot;\1\3 \4\5&quot; </instruction>
	</function>
</button>

Opus 12 & above – Method Two: Rename Preset

If, instead of a button, you want a rename preset you can use from the Rename dialog, then you should use this .orp file:

This is also the way to go if you want both a toolbar button and a rename preset. See Part 3, near the end of the post for that.


Part 2 -- Opus 11 and earlier

Unlike Opus 12, older versions did not have an option to preserve extensions while applying regular expressions, so the regex has to do that itself.

That means we need separate regular expressions for files and folders (since folders don't have extensions). It also means that multi-part extensions like .part1.rar won't be handled properly (the dot before the part1 will be removed). You could change the regex to handle multi-part extensions, but it would be a lot more complicated and would have to explicitly handle every possible multi-part extension.


Opus 11 & earlier -- Method One: Toolbar Button

If you want a toolbar button (or hotkey) which you can click to rename the selected items in this way then you should create a button which runs this command:

@NoDeselect
Rename REGEXP PATTERN="(.*)(([^0-9])\.|\.([^0-9]))(.*\..*)#" TO="\1\3 \4\5" TYPE=files
Rename REGEXP PATTERN="(.*)(([^0-9])\.|\.([^0-9]))(.*)#" TO="\1\3 \4\5" TYPE=dirs

(This button uses a rather complex regular expression. If you are new to regular expressions see this post for some much simpler examples: RegExp basics: Removing characters from start/end of names.)

Note that the button uses TYPE=files and TYPE=dirs to apply a different regular expression to files and directories. This is how it avoids removing the dot in a file's extension while still removing the last dot in a folder's name.

Here is the same button in XML format so that you can paste it on to your toolbar:

(See: How to add buttons from this forum to your toolbars)

<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>Dots to Spaces</label>
	<tip>Rename dots to spaces, except in numbers</tip>
	<icon1>#rename</icon1>
	<function type="normal">
		<instruction>@NoDeselect</instruction>
		<instruction>Rename REGEXP PATTERN=&quot;(.*)(([^0-9])\.|\.([^0-9]))(.*\..*)#&quot; TO=&quot;\1\3 \4\5&quot; TYPE=files</instruction>
		<instruction>Rename REGEXP PATTERN=&quot;(.*)(([^0-9])\.|\.([^0-9]))(.*)#&quot; TO=&quot;\1\3 \4\5&quot; TYPE=dirs</instruction>
	</function>
</button>

Opus 11 & earlier -- Method Two: Rename Preset

If, instead of a button, you want a rename preset you can use from the Rename dialog, then you should use this .orp file:

This is also the way to go if you want both a toolbar button and a rename preset. See Part 3, near the end of the post for that.

The attached rename preset uses VBScript to apply a regular expression to the items after preserving the file extension for safe-keeping (if a file is being renamed).

(If you edit the script, please note that VBScript's regular expression syntax is slightly different to the one used in Opus. There is no single regular expression syntax standard, unfortunately. See this post for more details on VBScript regular expressions: Script to perform multiple Regular Expressions.)


Part 3 -- All versions: Button which runs the preset

If you want to have both a toolbar button and a rename preset then you can create a button which refers to the preset, instead of defining the same regular expression (etc.) in two different places.

See the Using a Rename Preset outside the Rename Dialog section of How to use Rename Presets from this forum for ways to do this.


Part 4 -- All versions: Doing the reverse, Spaces to Dots

The reverse operation is trivial.

You can use a simple Find and Replace from a space to a dot.

The space in the Find field is highlighted to help you see it in the screenshot.

Or, as a command:

@NoDeselect
Rename FINDREP PATTERN=" " TO="."
1 Like

The top post has been updated for Opus 12, which has a better way to do this kind of rename.

The old methods for earlier versions have been kept, for people still using them.

I've also removed old replies to tidy up the thread, incorporating any extra info into the main thread.