iTunes users opting not to allow the program to automatically keep their folders organized (the default setting) may be well aware that iTunes does not respond well after changing locations of or renaming files. In fact, any change in the file name or path renders the item inaccessible from within iTunes. To make matters worse, there’s no easy way to have iTunes relocate files moved. iTunes prompts the user to relocate missing files but only one at a time with a dialog that says:
The song|movie “name” could not be used because the original file could not be found. Would you like to locate it?
Not so useful when a lot of files are moved at once. But if a directory containing hundreds of files needs to be moved, to a larger hard drive for example, locating files individually becomes too much work.
Of course, there’s always the “fresh start” approach. Just delete everything and start over… A good idea if iTunes ratings, playlists and play counts are not considered important keepsake. But to users who spend a good deal of time carefully tweaking song ratings and organizing playlists, scrapping their information and starting fresh may not be a desirable approach.
Thankfully there’s an easy workaround for the problem. A sane alternative to relocating files one at a time (like when you move hundreds or thousands of files). The workaround straightforward and reversible. And useful whenever moving many files together.
Applying it will allow users to move files around in bulk, while still hanging onto most of the iTunes metadata they have likely grown fond of.
Note:Some less significant meta information, such as Last Played time, is lost during the process.
Addressing the problem
Here are step-by-step instructions for updating the Library XML and recreate the iTunes Library to enable file relocation when iTunes files are manually organized.
Backup iTunes Music Library
Before you move your files, do the following:
- Close iTunes for now.
- Create copies of the following:
- (2x) Library XML (iTunes Music Library.xml)
- (1x) Library ITL (iTunes Library.itl)
Vista users can find the Library XML at C:\Users\<Username>\Music\iTunes
Mac users can find the Library XML at /Users/<Username>/Music/iTunes
Relocate iTunes files as necessary
Before moving files note the following two necessary pieces of information:
- The path where the files were previously stored (e.g. D:\Downloads\Music)
- The path where the files will end up (e.g. E:\Music\Archive)
Hack the Library XML and delete the Library ITL
After your files are moved, complete the following steps to implement the fix.
Tip: Do not open iTunes during this process.
- Open one of the Library XML copies created.
- Perform a Find/Replace using the following inputs:
Find: Path where files were moved from
Replace: Path where files were moved to - Save and close the document, noting which file contains the modifications.
- Delete the existing Library ITL.
Restart iTunes
Once the Library ITL has been deleted, restart iTunes. The application will open with a blank library; custom playlists, music and other items will be gone. To recover the data do the following:
- Import the modified copy of the Library XML.
In iTunes 8 and 9, choose File > Library > Import Playlist… - Navigate to and Open the modified Library XML.
- iTunes will then import the file contents into the blank library.
- Wait for the import to complete.
iTunes may display a dialog if any files cannot be located during the import process. The dialog can occur as a result of improper changes to the Library XML, or because the Library XML already contained references to files previously moved or renamed.
Wrapping up
Once the updated playlist is imported into iTunes lost songs and other media should be restored though there will be some duplicate playlists. Before deleting the extra playlists confirm the changes are working as expected. Once satisfied, delete the duplicates in the Library and enjoy your hard work. You’ve earned it.
If something goes wrong
If something goes wrong during the process, or if the results are not as expected, the original Library can be restored from the backup files created. To do so, close iTunes and copy the backup Library ITL and XML back to their original locations (overwrite existing files, if prompted) and restart iTunes to restore the previous Library.
Additional resources
Apple Support KB Article HT1451: How to re-create your iTunes library
This is a great little walkthrough! Itunes could do a lot to make things easier for us all…
Unfortunately it doesn’t quite apply when moving happens through forces beyond our control. Not that it claims to I lost part of my music collection.. and I had it on my ipod, but couldn’t get it back with the same directory structure… I managed to use a Music Rescue to copy over all the songs from the ipod, but it’s all Artist\Album\TrckNr – Title.mp3, and that’s not how it was originally. I was trying to use the same program to sync my files with my itunes library (it was having errors) when Itunes synced my iPod despite being told not to putting me up the creek.
I’m just wondering now about the advanced level of this tutorial now, where you run a find and replace on the xml, but replacing the file location with artist and title metadata? The way the itunes library.xml is structured ( being profoundly less useful than say, ) definitely doesn’t make this easy.. I wonder do you have any idea of how it could be done? (not sure if you have advanced scripting know-how or not.. but I’m really looking for a solution!
Sounds like you’re looking into methods for updating the file locations in the iTunes XML based on dynamic values taken from other parts of the file, such as artist/title nodes. While I haven’t done this personally you might have some luck using Python and one of the structured markup processing tools available for the language. Good luck!