Distinguish files and bundles

I use GetOpenFolderItem() to let the user pick file names. But it is possible to select either files, or bundles, with the same dialog.

Is there a way to I find out after selection by the user if a folderitem is a file, or a bundle ? I need that to process differently these items.

TIA

here is how to do it in a CARBON app… anyone have COCOA replacement?

  #if TargetCarbon
    Soft Declare Function LSCopyItemInfoForRef Lib CarbonFramework (byref inItemRef as fsRef, inWhichInfo as Integer, byref outItemInfo as lsItemInfoRecord) as Integer
    Dim theRef as FSRef
    Dim itemInfo as LSItemInfoRecord
    //
    Const kLSRequestBasicFlagsOnly = &hFFFFFFFF //&h00000004
    Const kLSItemInfoIsPackage = &h00000002
    //
    theRef = GetFSRefFromFolderItem(f)
    OSError = LSCopyItemInfoForRef(theRef, kLSRequestBasicFlagsOnly, iteminfo)
    If OSError <> 0 then
      //Raise new MacOSException("LSCopyItemInfoForRef", OSError)
    End if
    Return Bitwise.BitAnd(itemInfo.flags, kLSItemInfoIsPackage)=kLSItemInfoIsPackage
  #endif

[quote=43143:@Michel Bujardet]I use GetOpenFolderItem() to let the user pick file names. But it is possible to select either files, or bundles, with the same dialog.

Is there a way to I find out after selection by the user if a folderitem is a file, or a bundle ? I need that to process differently these items.

TIA[/quote]
Yes and yes. Once a bundle is correctly created, it will show up in a Open Dialog as a regular file. The easiest way to tell, is to check folder item.directory property as a bundle, being a folder will have this field set.

I had found MacType, but it is deprecated. Thank you for .directory :slight_smile:

I appreciate the effort, but Sam Rowlands replied with a simpler way, and it will not necessitate a declare. Will keep it in mind, though. Thkx.

For future reference, while this technique will work absolutely fine from the Open Dialog (because you have to use a different dialog to actually get folders), it may not be so reliable from Drag & Drop or if the user opens the application by dropping a folder/package/file onto the app icon.

However, once you’ve set up a file type object for your file type, you should be able to test folderitem.type to see if it matches.

This is a great method to avoid having different dialogs for folders and files. I shall experiment with that…