I've moved my iTunes library around from machine to machine for about four machines now, and in the process, many files get lost or missing. But iTunes keeps the references to those files around, resulting in the (to me) dreaded circle-exclamation-point icon, and the task of either finding the file or deleting the reference.
So I sat down and worked out this AppleScript...
tell application "iTunes"
set thePlaylist to library playlist 1
set musicFiles to the file tracks of thePlaylist
repeat with mf in musicFiles
--the name of mf as string
set hasLoc to ""
if (the location of mf as string ¬
is equal to "missing value") then
try
set comment of mf to the comment of mf & ""
on error number errNum
delete mf
end try
end if
end repeat
end tell
The script goes through the entire library looking for file tracks (stream tracks, for example) and first checks to see if the location of the file returns a missing value. If so, it then tries to append an empty string to the comment of the track (some file tracks return an empty value even though they aren't really empty). If that fails, the file is really missing and is deleted from the iTunes library. This is really the only option since iTunes cannot add a missing track to a playlist or alter the metadata for the track.
Mac OS X Hints
http://hints.macworld.com/article.php?story=2007031309145927