Please help me with this little script for adding the artist's name to files in a folder:
Option Explicit
dim objFSO
dim objFolder
dim objFileAny
dim strDirectory
dim strFileID
dim strFileName
dim strExtension
dim strArtist
dim strNewName
dim strMsg
strArtist = InputBox("Enter Artist")
strDirectory = InputBox("Enter Folder Path")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strDirectory)
strMsg = "New file names:" & vbNewLine
For Each objFileAny In objFolder.Files
strFileID = strDirectory & "\" & objFileAny.Name
strFileName = objFSO.GetBaseName(strFileID)
strExtension = objFSO.GetExtensionName(strFileID)
strNewName = strFileName & " - " & strArtist
strNewName = strNewName & "." & strExtension
objFileAny.Name = strNewName
strMsg = strMsg & strNewName & vbNewLine
Next
MsgBox strMsg
When I run the script commenting out "objFileAny.Name = strNewName" I get the results I want. When I put that line of code in SOME files seem to get renamed twice i.e. the artist's name is added twice e.g
"A Man Alone - Frank Sinatra - Frank Sinatra.wav
Option Explicit
dim objFSO
dim objFolder
dim objFileAny
dim strDirectory
dim strFileID
dim strFileName
dim strExtension
dim strArtist
dim strNewName
dim strMsg
strArtist = InputBox("Enter Artist")
strDirectory = InputBox("Enter Folder Path")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strDirectory)
strMsg = "New file names:" & vbNewLine
For Each objFileAny In objFolder.Files
strFileID = strDirectory & "\" & objFileAny.Name
strFileName = objFSO.GetBaseName(strFileID)
strExtension = objFSO.GetExtensionName(strFileID)
strNewName = strFileName & " - " & strArtist
strNewName = strNewName & "." & strExtension
objFileAny.Name = strNewName
strMsg = strMsg & strNewName & vbNewLine
Next
MsgBox strMsg
When I run the script commenting out "objFileAny.Name = strNewName" I get the results I want. When I put that line of code in SOME files seem to get renamed twice i.e. the artist's name is added twice e.g
"A Man Alone - Frank Sinatra - Frank Sinatra.wav