View Full Version : file attributes/properties viewer

Apr 8, 2007, 11:16 AM
i want to create a small app that will allow me to view and sort files on the mac by their various attributes/properties. eg, if you are viewing a folder full of mm3's in windows, you can choose detail view and select what attributes to sort the files by, such as bitrate, song duration, etc. the same is possible with images such as sorting by resolution or image format. Windows seems to be able to handle any file type like this. i need to know how are file properties/attributes stored on a mac? i know mp3's have tags( called ID3Tags), and there is something similar for images, but for all other files, is the information stored along with the file, or is it stored within the OS, and how is it viewed? ( i know there are applications that allow me to do this, but i want to do it for myself as a learning exercise)

Apr 8, 2007, 01:58 PM
Have a look at the docs for NSMetadataItem (https://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMetadataItem_Class/Reference/Reference.html).

When I was using this, I had to do a little bit in Carbon to actually get the attributes from a file, but I don't know if that's still necessary. Here is the code for a static utility method I wrote for that (returns metadata associated with a file in a Cocoa dictionary object):+ (NSDictionary*)metadataForFileAtPath:(NSString*)aFilePath {
MDItemRef item = MDItemCreate(kCFAllocatorDefault, (CFStringRef)aFilePath);
CFArrayRef metadataAttributeNames = MDItemCopyAttributeNames(item);
NSDictionary *metadataDict = (NSDictionary*)MDItemCopyAttributes(item, metadataAttributeNames);
return metadataDict;
}Some of the common metadata attributes for a file are here (https://developer.apple.com/documentation/Carbon/Reference/MetadataAttributesRef/index.html#//apple_ref/doc/uid/TP40001689). You use those names as keys to the dictionary, the values are the metadata as strings.