Folderexists( and Package "files"

Folderexists(path) is true if the path is for a folder. I want files like .pandb files to be treated as files, not folders. But Folderexists(…pandb) is true; I assume because .pandb “files” are package files… Is there a way to test a path to see if it is for a package file?

It’s really odd that you are asking this question now – I just needed to research this last night for my work on Panorama X server. So the answer is right on the tip of my fingers!

If a path is a package, like a .pandb file, both fileexists( and folderexists( will return true. So at the moment the only way to positively identify a file as a package is to perform both of those tests, if they are both true, the file is a package.

It sounds like maybe simply using fileexists( will do the job for you. The fileexists( function has special code to check whether a folder is a package, and if so, it returns true.

Here is another method to find the item type of file, folder or package using a shell script with the mdls command. The mdls command stands for metadata list and relies on the Spotlight stores for the data returned.

shellscript {mdls -name kMDItemContentTypeTree "/Users/gyon/Documents/test.pandb"}
message ?(ScriptResult contains "","Package",
    ?(ScriptResult contains "public.folder","Folder","File"))
1 Like

Wow, the kMDItemContentTypeTree returns a wealth of useful information! Thanks!