Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > getting cwd

getting cwd
Thread Tools
Fresh-Faced Recruit
Join Date: Apr 2002
Location: vancouver
Status: Offline
Reply With Quote
Apr 30, 2002, 01:05 PM
 
i need to see if a file exists in a directory where my app double clicked from, how do i determine this directory? I was using currentDirectoryPath but this only works from the debugger.[/LIST]
     
Senior User
Join Date: Jan 2000
Status: Offline
Reply With Quote
Apr 30, 2002, 02:12 PM
 
man 3 getcwd
     
Fresh-Faced Recruit
Join Date: Apr 2002
Location: Los Angeles, California
Status: Offline
Reply With Quote
May 1, 2002, 05:32 PM
 
Originally posted by djcornell:
<STRONG>i need to see if a file exists in a directory where my app double clicked from, how do i determine this directory? I was using currentDirectoryPath but this only works from the debugger.[/LIST]</STRONG>
I don't think the Finder sets the current working directory to anything useful when a user double-clicks your program to launch it. So the getting the current directory is useless.

Assuming you're writing a Cocoa application stored in an application bundle (directory called MyApp.app) you can use the following to find your path:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
NSString *pathname = [[NSBundle mainBundle] bundlePath];
</font>[/code]

If I remember correctly, the returned string will be the full pathname for the application bundle (ie. /Applications/MyApp.app)
--
Tim Buchheim
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:51 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2