• 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: Extracting file name & path from NSOpenPanel
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Extracting file name & path from NSOpenPanel


  • Subject: Re: Extracting file name & path from NSOpenPanel
  • From: Mike Abdullah <email@hidden>
  • Date: Sun, 2 Apr 2006 20:52:28 +0100

For an open panel you probably want to use filenames:

This will give you an array of the paths of the selected files. Do objectAtIndex: to get a particular path.

To get the file's name, you can call lastPathComponent on the filename string.

Hope that helps!
Mike.

On 2 Apr 2006, at 19:20PM, Phil Faber wrote:

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:
40gmail.com


This email sent to email@hidden

_______________________________________________ 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
References: 
 >Extracting file name & path from NSOpenPanel (From: Phil Faber <email@hidden>)

  • Prev by Date: Re: Extracting file name & path from NSOpenPanel
  • Next by Date: Re: Deletes Object on Remove option
  • Previous by thread: Extracting file name & path from NSOpenPanel
  • Next by thread: Re: Extracting file name & path from NSOpenPanel
  • Index(es):
    • Date
    • Thread