I recently lost over 10,000 music files and my backup was corrupted, so I had to recover the files using a third party program. This was successful. Unfortunately, I lost all of the filenames. Each music file still contains it's original file properties meaning the Title of the song still exists. I want to copy the Title of the song (from the file properties and use that as the filename. I have played around with coding using the following, but I get an error. I have all of the files stored in the root of my D:\ drive.
Will someone look at the code and make suggestions? Thank you!
Will someone look at the code and make suggestions? Thank you!
VBA Code:
Sub RenameFile()
Dim fso As Object
Dim folder As Object
Dim file As Object
Dim ext As String
Dim newName As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("D:\")
For Each file In folder.Files
ext = fso.GetExtensionName(file.Path)
If ext = "m4a" Then
newName = file.ParentFolder.Path & "\" & file.Title & ".m4a"
Name file.Path As newName
End If
Next file
Set fso = Nothing
Set folder = Nothing
Set file = Nothing
End Sub