2

I'm using Dropbox iOS API v2. When trying to sort out folders from files, files that are packages (i.e. a preferences file, or xcodeproject file, .framework, etc.) show up as folder types. Is there a way to distinguish between folders and file packages?

DBFILESMetadata * metaData = ...;
if ([metaData isKindOfClass:[DBFILESFileMetadata class]]) {
    // is a file
} else if ([metaData isKindOfClass:[DBFILESFolderMetadata class]]) {
    // is a folder or file package
} else if ([metaData isKindOfClass:[DBFILESDeletedMetadata class]]) {
    // has been deleted
}
2
  • One thought is that if it has a file extension, then it is not a folder. That may be good enough for this situation.
    – olynoise
    Commented Mar 24, 2017 at 0:19
  • [Cross-linking for reference: dropboxforum.com/t5/API-support/… ]
    – Greg
    Commented Mar 25, 2017 at 14:04

2 Answers 2

1

If the 'bundle' (B) bit is set, then it should be treated as a bundle, rather than a single file. However, not all 'packages' are 'bundles'.

See: How do I flag a folder as being a package?

If the package is used by an app that is installed on the device, then its extension should be registered in the system by that application to identify it as being a package folder rather than a plain folder. However, I'm not sure if you can identify these as packages from an app that does not have that particular type registered.

See: https://developer.apple.com/library/content/documentation/CoreFoundation/Conceptual/CFBundles/DocumentPackages/DocumentPackages.html

If the package is not a bundle and has an extension that is not registered by an app installed on the current device, then I don't think there is any method that can be certain to be accurate, and your work around of has-a-filename-extension is probably the only thing you can do.

1
  • Interesting! Do you have a code example for checking the bundle bit, rather than setting?
    – olynoise
    Commented Mar 24, 2017 at 17:37
0

This is what I ended up with.

DBFILESMetadata * metaData = ...;
if ([metaData isKindOfClass:[DBFILESFileMetadata class]]) {
    // is a file
} else if ([metaData isKindOfClass:[DBFILESFolderMetadata class]]) {
    if ([[metaData.name pathExtension] isEqualToString:@""] == NO) {
        // is a file package / bundle
    } else {
        // is a folder 
    }
} else if ([metaData isKindOfClass:[DBFILESDeletedMetadata class]]) {
    // has been deleted
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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