Re: Choosing Files Based Upon Type
Re: Choosing Files Based Upon Type
- Subject: Re: Choosing Files Based Upon Type
- From: "David W. Halliday" <email@hidden>
- Date: Mon, 18 Jun 2001 15:28:28 -0500
- Organization: Latin AmeriCom, formerly Latino Online
Joe Muscara wrote:
>
On Thursday, June 14, 2001, at 02:17 PM, Ali Ozer wrote:
>
>
> But rest assured that Cocoa is constantly being enhanced
>
> (for instance, in 10.0 open panel can now choose files based on types in
>
> addition to extensions).
>
>
While I did find this mentioned in the introductory text for the
>
NSOpenPanel help page, I haven't been able to figure out how to actually
>
implement it. All I could think of trying was
>
>
NSArray *fileTypes = [NSArray arrayWithObject:@"TEXT"];
>
>
but that resulted in the obvious - only allowing selection of items
>
whose extension was "TEXT."
>
>
How is this done? And, am I reading the original post correctly that
>
this has been available since 10.0?
>
>
Thanks!
>
Joe
Yes. Read the Mac OS X Cocoa AppKit Release Notes (at
<
http://Developer.Apple.com/techpubs/macosx/ReleaseNotes/AppKit.html>). Look
under "HFS File Type Strings".
There you will find functions defined in the Foundation framework (I
quote):
To support an environment in which the type of a file may be indicated by
either a file name extension or an HFS file type, a new form of file type
string has been introduced. The file type strings (traditionally file
extensions) that are accepted or returned by many Cocoa methods may now
contain an encoded HFS file type.
File type strings that contain a file name extension are still acceptable in
every situation in which they were acceptable before.
Several new functions, declared in <Foundation/NSHFSFileTypes.h>, have been
added to help manage these new file type strings:
NSString *NSFileTypeForHFSTypeCode(OSType hfsFileTypeCode);
Given an HFS file type code, this function returns an autoreleased string that
encodes the file type as described above.
OSType NSHFSTypeCodeFromFileType(NSString *fileTypeString);
Given a string of the sort encoded by NSFileTypeForHFSTypeCode(), this
function returns the corresponding HFS file type code. It returns zero
otherwise.
NSString *NSHFSTypeOfFile(NSString *fullFilePath);
Given the name of a file, this function returns an autoreleased string that
encodes the file's HFS file type as described above, or nil if the operation
was not successful.
Please use the above functions to convert between type codes and the special
encoded strings; do not depend on the exact format of the encoding type
string.
David email@hidden
P.S. There is much more of interest there, so be sure to read it all.