Advertisement

Filepaths under OSX

Started by June 11, 2009 06:01 PM
4 comments, last by swiftcoder 15 years, 5 months ago
I am using fstream and creating a file as such ofstream fout("error.txt"); problem is the file gets saved to the root dir if I am not mistaken? So what do I need to do to make sure it saves in the working dir? I tried this ofstream fout("../error.txt"); still nothing THanks I am new to the Unix file system vs. windows...
On *nix operating systems, relative paths are similar. To specify a file in the root of the file system use "/file". When you use "../file", you mean "file" in the parent folder, just like windows. Your original should open the file in the working directory.
Advertisement
Thanks rip-off, I still end up with files being saved to the root even with the ../path format? This is on OSX and Xcode3.1 if that would help nail it down?

Thanks
I remember Xcode doing odd things as far as setting the working directory. Do you get the same results running your code from within the IDE as you do executing it externally?
Quote: Original post by Matt328
I remember Xcode doing odd things as far as setting the working directory. Do you get the same results running your code from within the IDE as you do executing it externally?


Nope, in xcode the data is found correctly, but run the app without Xcode from its own directory and the files end up in the root dir? Don't tell me I need Boost or some api to determine the path? How was this all done in the past before Boost or apis if this is the case?

Thanks
Quote: Original post by MARS_999
Nope, in xcode the data is found correctly, but run the app without Xcode from its own directory and the files end up in the root dir? Don't tell me I need Boost or some api to determine the path? How was this all done in the past before Boost or apis if this is the case?
Mac applications aren't intended to be writing to arbitrary filesystem locations, and as such have no working path set (will default to the filesystem root, or the users home directory on older versions).

Log files should be written to '~/Library/Logs' (or /Library/Logs for a system-wide application, such as a server). Configuration and other runtime-generated data should be written to '~/Library/Application Data', and temporary data to '~/Library/Caches'.

All of this information is given (in considerable detail) in Apple's developer documentation.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement