Cocoa Application In Objective C ???

Discussion in 'Mac Programming' started by saurabhshukla, Apr 21, 2009.

  1. saurabhshukla macrumors newbie

    saurabhshukla

    Joined:
    Mar 20, 2009
    Location:
    India
    #1
    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.
     
  2. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #2
    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.
     
  3. saurabhshukla thread starter macrumors newbie

    saurabhshukla

    Joined:
    Mar 20, 2009
    Location:
    India
    #3
    Thank you CatFish Man i got your point. Thanks to help me.
     

Share This Page