A Quick Look into Developing Software at KLIK

Personal Posts Add comments

This little bit of code gets rid of songs that no longer exist in iTunes.

iTunesApp app = new iTunesApp();
 
IITTrackCollection tracks = app.LibraryPlaylist.Tracks;
foreach (IITTrack track in tracks)
{
	if (ITTrackKind.ITTrackKindFile == track.Kind)
	{
		IITFileOrCDTrack filetrack = (IITFileOrCDTrack)track;
		if (!File.Exists(filetrack.Location))
		{
			try
			{
				Console.WriteLine(track.Name + " - deleted");
				track.Delete();
			}
			catch
			{
				Console.WriteLine("Couldn't delete " + track.Name);
			}
		}
	}
}

While not a very robust solution, it gets the job done.

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in