Hello Orangeworker,
I apologize for the error. It appears the problem is due to a typo I made in the code. The code below has been corrected. The change has been marked in bold type.
Sub RenameFiles()
Dim FileName As String
Dim FilePath As String
Dim NewFileName As String
Dim RegExp As Object
Dim vFolder As Variant
Set RegExp = CreateObject("VBScript.RegExp")
RegExp.IgnoreCase = True
RegExp.Pattern = "(.+)(O\-.+)(\..*)"
FilePath = "E:\Publishing\Catalog\"
FileName = "Song One O-0001_Instrumental.mp3"
RegExp.Test (FileName)
NewFileName = RegExp.Replace(FileName, "$1$3")
For Each vFolder In Array("Vox", "Ins")
FileName = Dir(FilePath & vFolder & "\*.*")
While FileName <> ""
If RegExp.Test(FileName) Then
NewFileName = RegExp.Replace(FileName, "$1$3")
Name FilePath & vFolder & FileName As FilePath & vFolder & NewFileName
End If
FileName = Dir()
Wend
Next vFolder
End Sub
Bookmarks