From: matt@... (matt neuburg) Date: 2008-04-28T05:50:10+09:00 Subject: Re: Getting Mac file paths from disk... Vincent Angeloni wrote: > So when this finds a Numbers file, the result it gives is: > > ../filesizeTest/401k allocation.numbers > ../filesizeTest/401k allocation.numbers/QuickLook > ../filesizeTest/401k allocation.numbers/QuickLook/Thumbnail.jpg > ../filesizeTest/401k allocation.numbers/index.xml.gz > ../filesizeTest/401k allocation.numbers/document-thumbnail.tiff > ../filesizeTest/401k allocation.numbers/Contents > ../filesizeTest/401k allocation.numbers/Contents/PkgInfo > > I understand why this is happening (bundles and packages are folders > which the Mac OS treats like a file, but Ruby does not know about > this). The only "easy" solution that I can see to this is to use > rb-appscript and get the folder contents using Applescript (which > presumably *would* know to treat a package/bundle app as a file, > not a folder). I haven't tried this yet, and if anyone has, let > me know if it works! > > Has anyone else dealt with this problem and, if so, what solution > did you use? The Finder uses a number of different criteria to determine whether a folder should be portrayed to the user as a file: > The directory has a known extension: .app, .bundle, .framework, > .plugin, .kext, and so on. > The directory has its bundle bit set. > The directory has a known structure type indicating it is a modern or > versioned bundle. You wouldn't want to have to perform all those tests yourself, so the simplest thing is to use an API that can perform them for you. Your choice of rb-appscript and AppleScript is therefore a sensible one. Your code will probably look something like this: require 'rubygems' require "osax" sa = OSAX::ScriptingAddition.new("StandardAdditions") f = "/Users/mattneub/Desktop/newXcodeNotes.tao1" h = sa.info_for(MacTypes::FileURL.path(f)) puts h[:package_folder] #=> true f2 = "/Users/mattneub/Desktop/gcsc backups" h = sa.info_for(MacTypes::FileURL.path(f2)) puts h[:package_folder] #=> false Hope this helps - Of course if there's an installed Unix tool that does the same job, then you could use that, but I don't happen to know of one... m. -- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ Leopard - http://www.takecontrolbooks.com/leopard-customizing.html AppleScript - http://www.amazon.com/gp/product/0596102119 Read TidBITS! It's free and smart. http://www.tidbits.com