GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Modify Rename menu item script

I am a newbie to scripting. I would like to modify the Rename menu item that changes underscores to spaces. I would like to make it so that it can also change dashes ("-") and periods (".") in the filename to spaces.

This is probably simple for an experienced scripter, but I am at a loss as to how to do this.

Would somebody please help me with this by showing me exactly how to do it? I download a LOT of files and this would make my life a lot easier! I would be eternally grateful!!

Which version of Opus are you using? Your profile says 11 but I wanted to check in case it's just not updated.

It's possible in both Opus 11 and 12 but if you're using Opus 12 then there's a much easier method. (Due to wanting to replace dots, but presumably avoid replacing the dot before the file extension. In Opus 12 it's just a checkbox, while in Opus 11 it's a bit more complicated.)

Yes, I am using version 11 right now.

With Opus 11, a script is probably the best way to do it, if you want to preserve extensions with files (and not with folders).

Download this zip and extract the .orp (Opus Rename Preset) file inside it:

Various to (952 Bytes)

Then open the Rename dialog, and use File > Import to load the .orp file.

That should do what you want.

(This preset also works with Opus 12, of course.)

For reference, the script code which is inside the .orp file is also below.

This was based on a "Dots to Spaces" script I already had to hand, and it won't replace dots which are between numbers. So for example:

Hello.World.txt -> Hello World.txt
Directory-Opus_11.9-notes.txt -> Directory Opus 11.9 notes.txt

That's usually what you'd want, but if you want it to replace all dots, even ones in numbers, then it's a fairly simple change. Shout if you need help there.

[code]option explicit

Function Rename_GetNewName ( strFileName, strFullPath, fIsFolder, strOldName, ByRef strNewName )

Dim re
Dim strWordArray
Dim strExtension
Dim strNameOnly

' Create a RegExp object. See
Set re = new RegExp
re.IgnoreCase = True ' Case-insensitive matching.
re.Global = True ' All matches will be replaced, not just the first match.

' If we're renaming a file then remove the extension from the end and save it for later.
if fIsFolder or 0 = InStr(strFileName,".") then
	strExtension = ""
	strNameOnly = strFileName
	strExtension = Right(strFileName, Len(strFileName)-(InStrRev(strFileName,".")-1))
	strNameOnly = Left(strFileName, InStrRev(strFileName,".")-1)
end if

' Apply our regular expression to the filename.
' This replaces dots, unless they are between numbers.
re.Pattern = "([^0-9])\.|\.([^0-9])"
strNameOnly = re.Replace(strNameOnly, "$1 $2")

' Also replace underscores and dashes with spaces.
re.Pattern = "[-_]"
strNameOnly = re.Replace(strNameOnly, " ")

' Rejoin the name and extension and we're finished
strNewName = strNameOnly & strExtension

End Function[/code]

Thanks, but I can't figure out how to make it work. What I wanted was to add an item to the main Rename menu dropdown just like the current Underscores to Spaces is. It can even just replace the current one.

Even if that isn't possible, I can't figure out how to make your script work manually. I must be getting too old. :frowning:

If adding to the dropdown menu isn't possible, then it isn't worth the effort to go thru loading a script every time I want to rename a file. I'm sure I'm doing something wrong on that front, anyway. Sorry to be so hard-headed. :unamused:

I forgot the menu wasn't populated with presets automatically in Opus 11.

You can make a button in the menu which runs the preset using this command:

Rename PRESET="Various to Spaces"

(This assumes you have imported the preset into the dialog, then saved it as "Various to Spaces". Note that importing a .orp file doesn't save it into the list automatically; that's a separate step.)

I apologize again. Exactly what steps do I need to do to import a script as a preset? When I load it from the file menu in the rename dialog box, nothing seems to happen. I now have an item named 'Various to Spaces' in the Presets box, but I'm not sure it is attached to anything??? Also, exactly how do I 'run' that command you just gave me?

Please feel free to instruct me in a step-by-step manner as if I was a child. :blush:

OK, selecting 'Various to spaces' from the preset list does do the proper renaming, but I still have no idea how to run the command to add it to the menu.

Thanks for all your help. I really appreciate it.

How to add example buttons to your toolbars and menus has step-by-step instructions.

Please link your account if you need more detailed help.

Leo, you are the man!! Your button macro works great and just as expected. This will save me a lot of manual effort. Thank you so much!! :smiley: :smiley: :smiley: