Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Extracting file name & path from NSOpenPanel



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.