file attributes/properties viewer

Discussion in 'Mac Programming' started by schmintan, Apr 8, 2007.

  1. schmintan macrumors regular

    Mar 1, 2007
    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)
  2. HiRez macrumors 603


    Jan 6, 2004
    Western US
    Have a look at the docs for NSMetadataItem.

    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. You use those names as keys to the dictionary, the values are the metadata as strings.

Share This Page