• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Where the file is?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Where the file is?


  • Subject: Re: Where the file is?
  • From: Uli Kusterer <email@hidden>
  • Date: Sat, 19 Jan 2008 14:59:06 +0100

On 19.01.2008, at 14:10, Luca Ciciriello wrote:
1. ofstream ofs("ThreadLog.log");

That's a partial path, relative to the current working directory. Have you set the current working directory? You'd do that using the chdir() function.


When I launch my application, this instructions are executed, but I'm unable to locate where my file is written.

Well, the current working directory is set differently depending on how your app is launched. I think Finder and Xcode behave differently, one uses / and another uses the directory containing your app. You'll have to query the current working directory to find our where your app ends up, or just use an absolute path to make sure it ends up in a place where you want it.


Wich path I've to use in (1.) to see my file written in the same location where my app is?


If your application is a regular MacOS bundle, you could use NSBundle, which lets you get the path of your application bundle as an NSString. You can then get a char* containing this as a path that C++ understands using NSString's fileSystemRepresentation method.

But really, you shouldn't assume you can write to the directory where your app is. So, generally you should either ask the user where to put your files, or use a standard location, like Application Support, Documents, or in your case probably ~/Library/Logs/.

If you have other support files that are read-only, you'd best put them in your app bundle's "Resources" folder and use NSBundle's pathForResource:ofType: method to get an NSString with the absolute path to it, and then use that to actually access the path.

Cheers,
-- M. Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de




_______________________________________________

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


References: 
 >Where the file is? (From: Luca Ciciriello <email@hidden>)

  • Prev by Date: Re: System preferences panes on Leopard
  • Next by Date: Substitute a check box or a popup for as a field editor in a tableview
  • Previous by thread: Where the file is?
  • Next by thread: Substitute a check box or a popup for as a field editor in a tableview
  • Index(es):
    • Date
    • Thread