If you’re like me you’ve got thousands of songs in your iTunes library. I got a new notebook PC a couple months back, and I decided to move all my music to it since it’s got plenty of disk space. I know I had lots of songs in my library whose files didn’t exist anymore. There’s a script for removing dead tracks included with the iTunes COM download, so I figured I would port it over to a C# project.
The code is pretty straightforward. Get a reference to iTunes, check the file location of each track in the library and delete the tracks whose files don’t exist.
//create a reference to iTunes
iTunesAppClass iTunes = new iTunesAppClass();
//get a reference to the collection of all tracks
IITTrackCollection tracks = iTunes.LibraryPlaylist.Tracks;
for (int i = trackCount; i > 0; i–)
{
IITTrack track = tracks[i];
if (track.Kind == ITTrackKind.ITTrackKindFile)
{
IITFileOrCDTrack fileTrack = (IITFileOrCDTrack)track;
//if the file doesn’t exist, we’ll delete it from iTunes
if (fileTrack.Location == String.Empty || !System.IO.File.Exists(fileTrack.Location))
{
fileTrack.Delete();
}
}
}
You can download the project here (Download Project). I put it into a WinForm, used a worker thread to take care of the iTunes work because it can take some time to check a 10K song library, and output the dead tracks removed to a list box.

I think in part 2 I’ll add the ability to find duplicate songs and remove the copy with the lower bitrate. I know for sure that I’ve got quite a few of them. Any other ideas for what can be done with the iTunes SDK to clean up your music library or to just make life simpler?
Here’s what I used for this project:
Visual C# 2008 Express Edition
iTunes 7.4.2.4
iTunes COM for Windows SDK
FYI. I found about 175 dead tracks out of over 7300 in my library.
First. Let’s define FLOSS. It’s Free/Libre Open Source Software. The Wiki entry describes it much better than I could, so if you’re interested you can read more here.
The first FLOSS pick of the week is TrueCrypt. TrueCrypt is an open source disk encryption utility for Windows (2000, XP, Vista) and Linux. What I like about it is that you can create a virtual encrypted disk and save it to a single file. You can backup the file to CD, online, or wherever. What’s really cool is something called Traveler Mode. You can save your encrypted disk on a USB stick and run TrueCrypt right from the stick without having to install the app.
Very cool indeed.
Here’s an excellent article that 3 paths to career self-sabotage. Part of being a good developer has to include having a job! This article has motivated me to add a new point to the list of things I’m going to do to become a better developer. I’ll create a personal action plan for my professional development.
http://blogs.techrepublic.com.com/tech-manager/?p=340
Remember the scene from the Shining where the wife finds out what Jack Nicholson’s character has been working so hard on? Pages and pages of the text “All work and no play make Jack a dull boy.” As software developers we should all heed this warning.
As I was thinking about some of the things I could do to become a better developer, one item jumped to the forefront of my mind. Sometimes I just need to step away from the keyboard, get away from the code and recharge my batteries. For me, it might mean getting out in the fresh air for a walk with the dogs, reading a non-tech book, or watching the latest episode of 4400. It might be different for you, but whatever it is just make sure you get away from the code. Everyone loves to brag about their marathon code-fests depending on caffeine and sugar to make it through. Sometimes they’re necessary (usually due to poor planning), but they should never be thought of as normal or business as usual. As in all professions, software developers need a good work and home life balance. You’ll be OK in the short term without one, but eventually it will come back to haunt you.
I look at software developers as one part artist and two parts engineer. Most love what they do, and as a result will put in extremely long hours. I’m not naive. I know there will be times when you need to put in those extra hours to meet a deadline, but save yourself for those times it’s absolutely required. I’ll sometimes come up with some of my better ideas or more elegant solutions when I’m away from the keyboard. So Unplug. Get out of the chair and do something non-tech related. You’ll come back to your code refreshed and with new ideas.
Whenever I hear developers talking about how code and tech is their life, I get the exact opposite impression I think they’re trying to convey. Who wants to work with someone who can only interact with a compiler? Live life a little. There’s more to it than 1’s and 0’s.
If you regularly read many of the development blogs on the Internet, you’ve probably seen at least one entry devoted to how someone is going to be a better developer (usually in the next 6 months). In a nutshell, I’ll list some things I’ll do to make myself a better developer. I’ll use ideas I’ve gotten from others and some that I came up with on my own. My specialty is .NET development, so my list will come from that perspective.
- You’re reading it. I’m starting this blog. I already have a blog dedicated to sports, but this blog will give me the chance to write about tech and development topics that interest me.
- I’ll listen to more tech related podcasts. I’ve started to listen to Scott Hanselman’s Hanselminutes, and I’ll listen in on .NET Rocks more often. I’ve always been a fan of TWIT and Steve Gibson’s Security Now. Of course, I’ll keep listening to MacBreak Weekly.
- I’ll work on a non-work related project. I’ll work on a project that I’ll use for my own enjoyment or to solve a problem in my person computing life. I’ll also use tools or languages that I don’t already use at work to expand my skill-set.
- I’ll expand my use of unit testing with NUnit or some other application.
- Learn about and apply design patterns to my development projects.
- In addition to writing about development, read more about development best practices. That can be books, blogs, or magazines. As long as it’s good content, it doesn’t matter where it comes from.
- Participate in my local .NET user group.
- Share my new found knowledge with my fellow developers. Either at work or in community web sites.
- Create a self action plan for my career development.
I think if I stick with the items listed, I can’t help but become a better developer.