• 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: FW: NSFileManager
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FW: NSFileManager


  • Subject: Re: FW: NSFileManager
  • From: Greg Titus <email@hidden>
  • Date: Sun, 24 Jun 2001 11:03:57 -0700

On Sunday, June 24, 2001, at 10:40 AM, Aaron Tuller wrote:

an easier way to get to files in your Resources directory is [[NSBundle mainBundle] resourcePath]

-aaron

At 10:08 AM -0700 6/24/01, Tommy Braas wrote:
I am trying to use NSFileManager to get the current working directory path from a Cocoa application. I don't want to throw up a file chooser as I am trying to read a preferences file from within my application package. Whenever I use the following code the output is "/" when I run the application by double-clicking.

Aaron is right, but to explain a little more what is happening:

The NSFileManager -currentDirectoryPath method returns the current working directory that is passed in to the app as part of its environment when it is started up. This has nothing to do with where the Application is actually installed. ProjectBuilder explicitly sets this to the app directory, Finder explicitly sets this to "/", if you started the app from the command-line, the result from this method would be whatever directory you were currently in in the shell when you started the app.

Since you say you are trying to read a preferences file inside your app, you should use [[NSBundle mainBundle] pathForResource:ofType:], which will return the correct path inside your application, and also do the correct thing (look inside language directories) if the file you are looking for can be localized for different languages.

Hoep this helps,
--Greg


  • Follow-Ups:
    • RE: FW: NSFileManager
      • From: "Tommy Braas" <email@hidden>
References: 
 >Re: FW: NSFileManager (From: Aaron Tuller <email@hidden>)

  • Prev by Date: Confusion
  • Next by Date: Re: Matrix of NSTextFields (creating it in IB)
  • Previous by thread: Re: FW: NSFileManager
  • Next by thread: RE: FW: NSFileManager
  • Index(es):
    • Date
    • Thread