Techibee.com

Change the track name of music files using PowerShell

I went to my friend room last week to see cricket match. He got a new mobile phone and trying to copy all his favorite songs into it. After copying a few he realized that, file name that appearing his laptop and display name in phone are not same for songs he is copying. He disappointed and figureout that he has o change the title of each song by going to properties of each mp3 file. As I just sitting beside to him, he asked me if I can automate anything there to speed up the process. He has lot of MP3 files in such manner and thought of helping him with my favorite powershell scripting.

I authored a small script, which reads files of given extension type and changes the title of them to file name. So that music players shows the same name when playing…

$files = Get-ChildItem -Filter *.mp3 -Path c:MyMusic -Recurse
$wmp = New-Object -ComObject wmplayer.ocx

foreach ($file in $files) {
	$filename = $file.FullName
	$fileshortname = $file.Name.Split(".")[0]
	$metadata = $wmp.newMedia($filename)
	if ($metadata.name -ne $fileshortname) {
		Write-Host "Setting metadata"
		$metadata.name = $fileshortname

		}
	}
Exit mobile version