PoshCode Archive  Artifact [c444fc9180]

Artifact c444fc91806f443ef8f36f106393429f76ec5ea9087bf642cd253296182c3925:

  • File Remove-DeadITunesTracks.ps1 — part of check-in [745ab3a44d] at 2018-06-10 14:04:43 on branch trunk — This script will go through your ITunes library and check the paths for each of the Tracks. If it doesn’t find a file at the specified location it will remove that track from your ITunes Library. (user: Mark Schill size: 1033)

# encoding: ascii
# api: powershell
# title: Remove-DeadITunesTracks
# description: This script will go through your ITunes library and check the paths for each of the Tracks. If it doesn’t find a file at the specified location it will remove that track from your ITunes Library.
# version: 0.1
# author: Mark Schill
# license: CC0
# x-poshcode-id: 595
# x-archived: 2015-03-14T01:47:33
# x-published: 2009-09-20T23:51:00
#
#
Clear
$ITunes = New-Object -ComObject iTunes.Application

1..$ITunes.LibraryPlaylist.Tracks.Count | % {
	$CurrentTrack = $ITunes.LibraryPlaylist.Tracks.Item($_)

	# File Track ??
	if ( $CurrentTrack.Kind -eq 1 )
		{
		if ( ! ([System.IO.File]::Exists($CurrentTrack.Location)) ) 
			{
			Write-Host "$($CurrentTrack.Artist) - $($CurrentTrack.Name) has been deleted."
			$CurrentTrack.Delete()
			}
		}
	Write-Progress -activity "Removing Dead Tracks" -status "$($CurrentTrack.Artist) - $($CurrentTrack.Name)" -percentComplete ( $_/$ITunes.LibraryPlaylist.Tracks.Count*100)

}