Re: Irritating Problem with NSString Method and File Paths
Re: Irritating Problem with NSString Method and File Paths
- Subject: Re: Irritating Problem with NSString Method and File Paths
- From: Phil <email@hidden>
- Date: Mon, 4 Aug 2008 17:01:35 +1200
On Mon, Aug 4, 2008 at 4:43 PM, Patrick Walker <email@hidden> wrote:
> It seems that whenever I use Xcode to spawn the program, it is able to find
> the file but when spawning the program from Finder, it can never, ever find
> the file. I've been looking online and no one seems to have come across
> this before or maybe it's because it's so late that I'm not seeing the
> obvious.
>
This is because the current working directory is different when an
application is launched through Finder (vs. Xcode or the terminal).
You can check the current working directory with NSFileManager's
-currentDirectoryPath; Xcode sets this to the directory your
application bundle is in, Finder sets it to "/".
I'd recommend using NSBundle to figure out where your application, and
use the NSString path manipulation methods:
[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:filename]
Phil
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden