Extracting file name & path from NSOpenPanel
Extracting file name & path from NSOpenPanel
- Subject: Extracting file name & path from NSOpenPanel
- From: Phil Faber <email@hidden>
- Date: Sun, 2 Apr 2006 19:20:50 +0100
Hi all.
I'm a newbie and I am trying to figure out how to prompt the user to
select a file name, and then display that name (including path) in an
Alert box. (The alert box is only used to see if the code was
successful - eventually it will be replaced by something more useful!)
I've managed to get as far as this code (which displays the file's
CONTENTS), but how can I get at the file NAME and path?
Thanks!
-
// Select file to compress
{
// Create and display an open panel.
NSOpenPanel *panel = [NSOpenPanel openPanel];
int result = [panel runModalForDirectory:nil file:nil types:nil];
// Quit if user pressed cancel.
if ( result == NSFileHandlingPanelCancelButton )
{
[NSApp terminate:self];
}
// Read the file and put it in the text view.
NSString *content = [NSString stringWithContentsOfFile:[panel
filename]];
NSRunAlertPanel(@"File name selected was:",content,@"OK",NULL,NULL);
}
-
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden