Re: NSFileManager
Re: NSFileManager
- Subject: Re: NSFileManager
- From: jgo <email@hidden>
- Date: Thu, 28 Jun 2001 23:38:08 -0700
>
Greg Titus <email@hidden> Sun, 2001-06-24 11:03:57 -0700
>
> On Sunday, 2001 June 24 at 10:40, Aaron Tuller wrote:
>
>> At 2001-06-24 10:08 -0700, Tommy Braas wrote:
>
>> I am trying to use NSFileManager to get the current working directory
>
>> path from a Cocoa application... 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.
>
> an easier way to get to files in your Resources directory
>
> is [[NSBundle mainBundle] resourcePath]
>
>
>
> -aaron
>
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.
This is good to know. Thanks.
>
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...
And what if you were trying to find what types of resources are
available there? I can see some applications allowing users to
optionally provide certain kinds of resources and needing to
grope about to see how many of which kinds are there.
John G. Otto Nisus Software, Engineering
www.infoclick.com www.mathhelp.com www.nisus.com software4usa.com
EasyAlarms PowerSleuth NisusEMail NisusWriter MailKeeper QUED/M
Will program Macs for food.