Rename script not working

The following rename script stopped working - it makes no changes to the file name when applied - with 13.14.1

option explicit

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

	Dim re
	Dim strWordArray
	Dim strExtension
	Dim strNameOnly

	' Create a RegExp object. See http://msdn2.microsoft.com/en-us/library/ms974570.aspx
	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
	else
		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

Appreciate any help!

Rewriting seemed easier than debugging :slight_smile:

Give this a try:

// https://resource.dopus.com/t/rename-script-not-working/55235

function OnGetNewName(getNewNameData) {
    var tmpStem = getNewNameData.newname_stem;
    var tmpExt = getNewNameData.newname_ext;

    tmpStem = tmpStem.replace(/([^\d])\.|\.([^\d])/g, '$1 $2');
    tmpStem = tmpStem.replace(/[-_]/g, ' ');

    return tmpStem + tmpExt;
}

55235.orp

1 Like

Perfect, thanks!

The original should work again in the latest beta, too. VBScript rename scripts that used the old entry point got broken by mistake.

1 Like

Thanks Leo!

1 Like