Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

This is a question from Wil Wheaton's google+, but I would like to get an answer too, stackexchange style.

Suppose you have all your music in a folder called /iTunes/Music. When you add files to iTunes, it puts them inside this folder, so it looks like this: /iTunes/Music/artist/album/track

Suppose you recently eliminated about 10GB of music from your iTunes library, but stupidly left those files inside /iTunes/Music. You have the entire thing backed up and pristine on an external drive, so you don't need to keep that music in that folder.

Here's the question: you want to write a script that will compare your iTunes library to the contents of /iTunes/Music, identify files that are in /iTunes/Music but not the iTunes Library file, and move them to a new folder (probably in /tmp) so you can take a look, then delete them.

One possible solution would be to write a script which puts the output of ls (with appropriate flags) into a file, then diff that file with the contents of Library.xml, and move the resulting files into a new directory. Is it possible to do this?

Maybe there is already an Applescript which can be used to achieve this?

share|improve this question

2 Answers 2

You could move the location of your iTunes Media folder, which will only move those files actually in the iTunes library.

It may take a while, even if the source and destination are both on the same drive (it's still got to tell the OS to move each file individually), but should leave behind any files that aren't in the library.

The iTunes Media folder location is set in iTunes Preferences, under the Advanced tab. This will of course only work if you have "Keep iTunes Media folder organized" checked (which judging by your question is the case).

I would suggest something as simple as changing just the name of the folder it's currently set to (i.e. keep it somewhere in your home folder, or whatever drive it's currently on), and then move it back after you've cleaned out the 'orphaned' files.

share|improve this answer
    
After you change the folder you'll need to run Organize Library with the Consolidate Files option checked. Full instructions are here: support.apple.com/en-us/HT201562 –  Nate Dec 4 at 8:31

Try this script. It's from Doug's AppleScripts. I never used it, but sounds like what you are looking for.

share|improve this answer
    
Whilst your answer may theoretically answer the question, it would be preferable to include the essential parts of the article in an answer below, and provide the link for reference –  Pfitz Dec 5 '12 at 7:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.