• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to distinguish if a file is a Document or an Application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to distinguish if a file is a Document or an Application


  • Subject: Re: How to distinguish if a file is a Document or an Application
  • From: Alex <email@hidden>
  • Date: Wed, 19 Mar 2003 13:49:59 -0800

Sorry if you didn't understand it that way, but an "App directory", one
kind of bundle, is an executable to the underlying Operating System,
being OSX. I am sure others will be able to confirm the suggestion or
provide the correct answer instead ;)

However what I do not understand is why, if you are only after looking
if a f i l e is an executable, you even look at anything other than
files in the first place, which seems like a waste to me. I think it
would help if you provided more on your query.

Alex



>> the underlying operating system


Alex

On Wednesday, March 19, 2003, at 01:27 PM, David Remahl wrote:

> From: David Remahl <email@hidden>
> Date: Wed Mar 19, 2003 1:27:58 PM US/Pacific
> To: Alex <email@hidden>
> Cc: email@hidden, John MacDonnell <email@hidden>
> Subject: Re: How to distinguish if a file is a Document or an
> Application
>
> Unfortunately, that is not the correct interpretation of the
> documentation. The term executable in this case, refers to wether the
> file system node (wether it is a file or a directory) has its
> executable bit set.
>
> The following code and its output shows how the function behaves:
>
> --- tmp.m ---
> #import <Foundation/Foundation.h>
>
> int main( int argc, char **argv ) {
> NSAutoreleasePool *autoPool = [[NSAutoreleasePool alloc] init];
> NSFileManager *fm = [NSFileManager defaultManager];
> NSArray *checks = [NSArray arrayWithObjects:
> @"/Applications/",
> @"/Applications/Mail.app",
> @"/Applications/Mail.app/Contents/MacOS",
> @"/Applications/Mail.app/Contents/Info.plist",
> @"/private/var/root",
> @"/usr/bin/env",
> @"/Applications/iTunes.app",
> @"/Mac OS 9/Applications (Mac OS 9)/Graphing
> Calculator",
> nil];
> NSEnumerator *checksEnum = [checks objectEnumerator];
> NSString *currPath;
>
> while( currPath = [checksEnum nextObject] )
> NSLog(@"Path: %@ Executable: %@", currPath, [fm
> isExecutableFileAtPath:currPath] ? @"YES" : @"NO" );
>
> return 0;
> }
> --------
>
> % cc -o tmp -framework Foundation tmp.m; ./tmp
> 2003-03-19 22:21:46.746 tmp[4697] Path: /Applications/ Executable: YES
> 2003-03-19 22:21:46.747 tmp[4697] Path: /Applications/Mail.app
> Executable: YES
> 2003-03-19 22:21:46.748 tmp[4697] Path:
> /Applications/Mail.app/Contents/MacOS Executable: YES
> 2003-03-19 22:21:46.749 tmp[4697] Path:
> /Applications/Mail.app/Contents/Info.plist Executable: NO
> 2003-03-19 22:21:46.749 tmp[4697] Path: /private/var/root Executable:
> NO
> 2003-03-19 22:21:46.750 tmp[4697] Path: /usr/bin/env Executable: YES
> 2003-03-19 22:21:46.751 tmp[4697] Path: /Applications/iTunes.app
> Executable: YES
> 2003-03-19 22:21:46.752 tmp[4697] Path: /Mac OS 9/Applications (Mac OS
> 9)/Graphing Calculator Executable: YES
>
> As you can see, -isExecutableFileAtPath: returns YES even if used on
> for examples the Applications directory. That is what enables you to
> traverse through it (which is the directory manifestation of the
> executable property). Info.plist and /private/var/root do not have the
> executable bit set for a regular admin user, and thus they return NO.
>
> A set of tests that I can think of to determine wether a particular
> "file" (meaning bundle or file) is an Application from the viewpoint
> of the Finder are these: (if any of the following is true, then the
> file is an Application).
>
> - Has an HFS file type of 'APPL'
> - Has a file extension of .app, and has a bundle structure
>
> / Rgds, David Remahl
>
>> From the Cocoa reference on NSFileManager:
>>
>> isExecutableFileAtPath:
>>
>> - (BOOL)isExecutableFileAtPath:(NSString *)path
>>
>> Returns YES if the underlying operating system appears able to execute
>> the file specified in path and NO if it cannot. This method traverses
>> symbolic links.
>>
>> ==
>> so, you should be able to do this then....
>>
>> BOOL isExecutableOrNot = [[NSFileManager defaultManager]
>> isExecutableFileAtPath:@"/Volumes/somevolume/myapp.app"];
>>
>> =
>>
>> On Wednesday, March 19, 2003, at 10:50 AM, John MacDonnell wrote:
>>
>>> From: John MacDonnell <email@hidden>
>>> Date: Wed Mar 19, 2003 10:50:18 AM US/Pacific
>>> To: email@hidden
>>> Subject: How to distinguish if a file is a Document or an Application
>>>
>>> Hello gurus,
>>> I'd like to understand from a given path if the file addressed by
>>> the
>>> path is a Document or an Application.
>>>
>>> can you help me in that? the problem is than in Mac OS X applications
>>> are directories (bundle) but they might be single file too if they
>>> are
>>> carbon ones. how to distinguish Apps from directories..
>>>
>>> thanks and see you on WWDC!
>>>
>>> Giovanni
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: How to distinguish if a file is a Document or an Application (From: David Remahl <email@hidden>)

  • Prev by Date: Re: How to distinguish if a file is a Document or an Application
  • Next by Date: NSTextField
  • Previous by thread: Re: How to distinguish if a file is a Document or an Application
  • Next by thread: Re: How to distinguish if a file is a Document or an Application
  • Index(es):
    • Date
    • Thread