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

trey5498

macrumors regular
Original poster
Jun 16, 2008
191
0
How do I get the current working directory of the application? in the command or shell line it is "./test.txt" However setting that to a path doesnt seem to work.

I have seen:

GetCurrentDirectory, but I can't seem to track that one down either. Any ideas?
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
On most unix systems you can get the environment variable PWD with getenv. This may also work, but I am not familiar with how it behaves:
Code:
NSString *myPath = [[NSBundle mainBundle] bundlePath];

Lee
 

trey5498

macrumors regular
Original poster
Jun 16, 2008
191
0
On most unix systems you can get the environment variable PWD with getenv. This may also work, but I am not familiar with how it behaves:
Code:
NSString *myPath = [[NSBundle mainBundle] bundlePath];

Lee

How to obtain just the path and not the file name?
 

trey5498

macrumors regular
Original poster
Jun 16, 2008
191
0
Code:
NSString *myPath = [[NSBundle mainBundle] bundlePath];

got the path in one line where getcwd wanted to do it in like 3 and I kept getting errors. I am trying to do it in as much cocoa as I can.
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
Can't you use

Code:
NSString *curDir = [[NSFileManager defaultManager] currentDirectoryPath];

? Or is that not the same thing?
 

saurabhshukla

macrumors newbie
Mar 20, 2009
12
0
India
Not working in my code?????

Hi Guys i tried both
Code:
NSString *myPath = [[NSBundle mainBundle] bundlePath];
&
NSString *curDir = [[NSFileManager defaultManager] currentDirectoryPath];
Earlier due to some mistakes these were not getting work but now working. Thanks to all.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.