Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

saurabhshukla

macrumors newbie
Original poster
Mar 20, 2009
12
0
India
Hi i am creating a Cocoa application in Objective C using XCode. In this project i am writing some text in the sample.txt file which is located at the current directory i.e. if my .app(application) file is at desktop then sample.txt is also at Desktop.

I am getting current directory path using this code line
NSString *curDir = [[NSFileManager defaultManager] currentDirectoryPath];
then i am appending @"/sample.txt" string.

Now when we build project using "Build & Go", text is getting write into file sample.txt located at current directory. But if we stop application & run built .app file (Like .exe file in Windows) it does not write file sample.txt at the current directory while it tries to find out sample.txt at root folder (In Macintosh HD).

Now i want that my built .app (Like .exe) file should write sample.txt only at current directory of my application.


Why its not getting work please help me out. Any help is appreciated. Thanks in advance.
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
Running an application does not set the current working directory. You'll need to get the bundle path and remove the last path component from that.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.