iTunes library pointing to completely wrong files Somewhere along the way, a significant portion of the songs in my iTunes library seem to be pointing to completely incorrect files (1640 of 9160, to be exact). I know there are tools and means for fixing files that are simply in a new/different folder and still have the same filename, but is there an easy/automated way to fix thousands of songs that are pointing to completely unrelated files?

Example from iTunes Library.xml:

    &lt;dict&gt;
        &lt;key&gt;Track ID&lt;/key&gt;&lt;integer&gt;13712&lt;/integer&gt;
        &lt;key&gt;Name&lt;/key&gt;&lt;string&gt;Lover's Spit&lt;/string&gt;
        &lt;key&gt;Artist&lt;/key&gt;&lt;string&gt;Broken Social Scene&lt;/string&gt;
        &lt;key&gt;Album Artist&lt;/key&gt;&lt;string&gt;Broken Social Scene&lt;/string&gt;
        &lt;key&gt;Album&lt;/key&gt;&lt;string&gt;You Forgot It In People&lt;/string&gt;
        &lt;key&gt;Genre&lt;/key&gt;&lt;string&gt;Indie&lt;/string&gt;
        &lt;key&gt;Kind&lt;/key&gt;&lt;string&gt;MPEG audio file&lt;/string&gt;
        &lt;key&gt;Size&lt;/key&gt;&lt;integer&gt;11613871&lt;/integer&gt;
        &lt;key&gt;Total Time&lt;/key&gt;&lt;integer&gt;382302&lt;/integer&gt;
        &lt;key&gt;Disc Number&lt;/key&gt;&lt;integer&gt;1&lt;/integer&gt;
        &lt;key&gt;Disc Count&lt;/key&gt;&lt;integer&gt;1&lt;/integer&gt;
        &lt;key&gt;Track Number&lt;/key&gt;&lt;integer&gt;11&lt;/integer&gt;
        &lt;key&gt;Year&lt;/key&gt;&lt;integer&gt;2002&lt;/integer&gt;
        &lt;key&gt;Date Modified&lt;/key&gt;&lt;date&gt;2012-07-25T18:48:35Z&lt;/date&gt;
        &lt;key&gt;Date Added&lt;/key&gt;&lt;date&gt;2010-10-20T18:39:51Z&lt;/date&gt;
        &lt;key&gt;Bit Rate&lt;/key&gt;&lt;integer&gt;241&lt;/integer&gt;
        &lt;key&gt;Sample Rate&lt;/key&gt;&lt;integer&gt;44100&lt;/integer&gt;
        &lt;key&gt;Comments&lt;/key&gt;&lt;string&gt;Source: eMusic&lt;/string&gt;
        &lt;key&gt;Play Count&lt;/key&gt;&lt;integer&gt;7&lt;/integer&gt;
        &lt;key&gt;Play Date&lt;/key&gt;&lt;integer&gt;3427320429&lt;/integer&gt;
        &lt;key&gt;Play Date UTC&lt;/key&gt;&lt;date&gt;2012-08-09T08:27:09Z&lt;/date&gt;
        &lt;key&gt;Album Rating&lt;/key&gt;&lt;integer&gt;60&lt;/integer&gt;
        &lt;key&gt;Album Rating Computed&lt;/key&gt;&lt;true/&gt;
        &lt;key&gt;Artwork Count&lt;/key&gt;&lt;integer&gt;1&lt;/integer&gt;
        &lt;key&gt;Persistent ID&lt;/key&gt;&lt;string&gt;B664192E9854A1F1&lt;/string&gt;
        &lt;key&gt;Track Type&lt;/key&gt;&lt;string&gt;File&lt;/string&gt;
        &lt;key&gt;Location&lt;/key&gt;&lt;string&gt;file://localhost/Applications/_Productivity/Pages.app/Contents/Resources/Templates/Modern%20Photographer%20Invoice.template/Contents/Resources/zh_TW.lproj/&lt;/string&gt;
        &lt;key&gt;File Folder Count&lt;/key&gt;&lt;integer&gt;10&lt;/integer&gt;
        &lt;key&gt;Library Folder Count&lt;/key&gt;&lt;integer&gt;3&lt;/integer&gt;
    &lt;/dict&gt;


Notice the Location node, in particular. It's pointing to a Pages template file rather than its MP3 file: file:///Users/administrator/Music/Broken%20Social%20Scene/You%20Forgot%20It%20In%20People/11%20Lover's%20Spit.mp3. 

Not even close to what it should be!

I've already tried the following things, to no avail:


Re-add Music folder to library — Unfortunately, this leaves me with duplicated entries. The broken item still remains, with play counts, ratings, etc. and the new item is started over from scratch. Not really ideal.
TuneUp and Rinse — I tried running it through the trials of TuneUp and Rinse, which didn't seem to catch on to the problem I was having.


My last resort idea is to setup a script that parses the XML and checks for non MP3 Location strings. When one is found, attempt to re-construct the filename based on iTunes's automatic filenaming convention (e.g. Lover's Spit above becomes 11%20-%20Lover's%20Spit.mp3. This likely would get me 90-95% there. The remaining items could be manually fixed.

Of course, that would involve a lot of scripting time and trial and error. I'm hoping there's a simpler solution to my problem.

Ideas?
I would suggest a combination of your first and last ideas. You could re-add your Music folder to your library, and then use a script to change the location of the old entries (correct metadata) to the new entries (correct locations).

Pseudocode rough draft:

for every song in the XML file (seek)
  search the rest of the XML file for other songs of the same name
  if only one is found (found)
    log seek's name to file1
    if found is newer than seek
      copy found's Location value to seek
      remove found
    else
      copy seek's Location value to found
      remove seek
  else if more than one is found
    log seek's name to file2 (for manual editing)
  else (no others are found)
    log seek's name to file3


This script design would assuredly be quite inefficient, but it would fix most problems itself, and you would (er, should) only have to review the songs with more than 2 duplicate versions.

See this answer for details on how to make these XML changes take effect on your library.