Re: How to distinguish if a file is a Document or an Application
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: David Remahl <email@hidden>
- Date: Wed, 19 Mar 2003 22:27:58 +0100
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.