Tracking moved files: An interesting tidbit on file references in OS X

Published 13 February 09 11:14 AM | mrdecav

Today I had to help someone with a problem with iTunes on Windows.  For those of you that have not had the pleasure of using iTunes on Windows, it sucks, like most software written by Apple for Windows.  That being said, this problem really had nothing to do with iTunes.  The problem was that iTunes was 'losing' music.  As it turns out, the music that the user saw as 'lost' turned out to have been moved from its original location (the desktop) to the 'Music' folder.  iTunes uses absolute paths in its media library to hold reference to the file.  When the file moves, the reference is broken, and thus, the music appears 'lost'.  Without iTunes open all the time (and due to the occasionally unreliable file system watcher), it is simply not possible to track these files.

But then I started wondering... Surely Apple wouldn't let this happen on OSX.  Details like this tend to be a place where Apple shines.  So what in the world does iTunes do if I move something from the 'Music' folder to my 'Desktop' in OSX.  I decided to try.  First I closed iTunes, then I copied a music file, went back to iTunes, and hit play.  Low and behold, it played, no problem.  Not only did this leave me confused, but it also left me interested, so I decided to do a little exploring...

From what I can tell, Apple foresaw this problem with their 'aliases' early on in their original Mac OS, so rather than referencing files by path, you can reference files by a unique ID (if they are on a partition that uses a supported file system).

I'm no expert on Cocoa, but from what I can tell, the details of this can be found in the File Manager APIs and FSRef.

And for some more interesting reading on the topic.

So next time you get the dreaded 'cannot find the target to this shortcut, do you want to try to find the file?' prompt, just think about those 1980's Apple employees and how they solved this problem...

Filed under: , ,

Comments

# Anonymous said on February 13, 2009 07:38 PM:

You're too hard on Windows.  WMP is *way* more graceful about this than iTunes for Windows is.  WMP watches the file system in some directories you specify, and will update any changes to them automatically.  So, for instance, if you specify c:\music as your music folder and move things around inside its subfolders (or to and from the User\Me\Music folder, WMP will track it.  It will also *always* know if you delete a file and remove the song from the library, unlike iTunes, which will keep it around and give you errors when you try to click the missing song.

I always point to this as my biggest example of why iTunes sucks.  Even the out-of-the-box WMP is smart enough to handle this.

# mrdecav said on February 14, 2009 12:09 AM:

@Daniel I agree WMP is better about this.  I did say iTunes sucks on Windows...  Apple can't make Windows software for anything...

That being said, WMP can only tack file moves while its open...  OSX can maintain it it when iTunes is closed.

Leave a Comment

(required) 
(required) 
(optional)
(required)