Rename problem

Hi, everybody! I want to rename like this:
Beauty%20and%20the%20 Beast%20-%20Walt%20Disney%20[HGY_YY%2008634218135630468750_128][1].vol1.mkv --> Beauty and the Beast - Walt Disney.vol1.mkv

I create this button:

Rename PATTERN (.*)(%20)(.*)# TO "\1 \3" REGEXP TYPE=files Rename PATTERN (.*)-(.*)(\s|\[[A-Za-z0-9\s_-]{1,}\]*)(\..*)# TO "\1-\2\4" REGEXP TYPE=files @nodeselect
And it works, but when I put above code into VBScript like this:

@nodeselect Rename TO="*" @script vbscript Function Rename_GetNewName ( strFileName, strFullPath, fIsFolder, strOldName, ByRef strNewName ) Dim re Set re = new RegExp re.IgnoreCase=True re.Global=True re.Pattern = "(.*)(%20)(.*)" strNewName = re.Replace(strFileName, "$1 $3") re.Pattern = "(.*)-(.*)(\s|\[[A-Za-z0-9\s_-]{1,}\]*)(\..*)" strNewName = re.Replace(strNewName, "$1-$2$4") End Function
It still works, but I have to click the button several times to have the expected result. What's wrong with it?

By the way, how can I turn on "Enable file information fields" (to rename some music files) in VBScript?

Please help me, thanks a lot.

It seems that VBScript's regexp object doesn't replace all matches if the expression covers the entire string, so only one %20 is being turned into a space.

Change this:

re.Pattern = "(.*)(%20)(.*)" strNewName = re.Replace(strFileName, "$1 $3")

To this:

re.Pattern = "%20" strNewName = re.Replace(strFileName, " ")

You can't use fileinfo in VBScript directly, pass it into the script via as part of strNewName. See here.

Hi, Leo. Thanks for your rapid reply.

You mean I should fix my code like this:

@nodeselect Rename TO="*" @script vbscript Function Rename_GetNewName ( strFileName, strFullPath, fIsFolder, strOldName, ByRef strNewName ) Dim re Set re = new RegExp re.Global=True re.IgnoreCase=True re.Pattern = "%20" 'line 9 strNewName = re.Replace(strFileName, " ") 'line 10 re.Pattern = "(.*)-(.*)(\s|\[[A-Za-z0-9\s_-]{1,}\]*)(\..*)" 'line 11 strNewName = re.Replace(strFileName, "$1-$2$4") 'line 12 End Function
It works with line 9, 10 only (replace %20 with space), when you add line 11, 12 into the code, it does not work. I don't understand this at all.

Easier solutions are better solutions. I refuse to go further with VBScript in this case, I use the other way in my #1 post instead.
I thought VBScript was the best way to do such these things but I was wrong, other built-in things (not VBScript) in DO are really better in this case. We shouldn't waste our time any more, should we?

Good time, thanks!

I think your regexp on lines 10 and 11 is wrong, and it's matching the wrong thing (or not matching at all).

You probably don't want the \s| at the start of it, but I'm not sure. Don't have time to debug a complex regexp right now, sorry .:slight_smile: