how does Mac OS X handle relative file paths?

Member
Posts: 321
Joined: 2004.10
Post: #1
This is probably trivial, but I'm probably searching with wrong parameters.


How does OS X handle relative path names. Is there some way
of retrieving the current path name for the game app?

Right now, I'm doing something like the following:

string path = "/Users/PNG/Planes/Data/"; // hard coded for now
imageFile = path + token + ".png";

So in other words, let's say may game app is in a folder GAME, and I want
to access images in a folder DATA contained in this game folder.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #2
I do
Code:
scriptPath = [[NSBundle mainBundle] bundlePath];
scriptPath = [scriptPath stringByDeletingLastPathComponent];
scriptPath = [scriptPath stringByAppendingString:@"/"];
script = [NSString stringWithContentsOfFile:[scriptPath stringByAppendingString:@"main.lua"]];

to get a script file in the same folder as the application package as the game
the entire source is here
http://www.geocities.com/ed72678954/Grid...Source.tgz

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 321
Joined: 2004.10
Post: #3
Don't mean to sound unappreciative, but if this Cocoa or objective
C code, It's greek to me. Anybody have a Carbon/C/C++ example?

One day I'll jump into Cocoa. SDL is next though.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #4
Code:
#include <Carbon/Carbon.h>
#include <limits.h>

CFURLRef bundleURL;
UInt8 bundlePath[PATH_MAX];

bundleURL = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFURLGetFileSystemRepresentation(bundleURL, 1, bundlePath, PATH_MAX);
CFRelease(bundleURL);
Quote this message in a reply
Member
Posts: 131
Joined: 2004.10
Post: #5
On the mac directories are separated by a ":" not a "/" (unix) or "\" (windows). There are other rules which I'm not familiar with. Everyone here loves to give a carbon or cocoa solution instead of giving the standard lib information. I'm still looking for all the rules for pathing on a Mac when using fopen and other standard C library functions.
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #6
that's not true, they are seperated by /

also, if you right a filename in the finder with a / in it, look at it with ls in the terminal, and you'll find it's been replaced with a :

It's not magic, it's Ruby.
Quote this message in a reply
Member
Posts: 131
Joined: 2004.10
Post: #7
Nayr Wrote:that's not true, they are seperated by /

also, if you right a filename in the finder with a / in it, look at it with ls in the terminal, and you'll find it's been replaced with a :

In a terminal, it will behave like any unix terminal (bash or c shell or whatever.) using unix's way of displaying the paths and all that rot.

If you do fopen("dolt/mydamnfile.txt", "w"); it will create a file call "dolt/mydamnfile.txt" in the current directory instead of creating a file "mydamnfile.txt" in directory "dolt". I'm assuming dolt already exits. Or at least this has been my experience so far.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
It's kinda true -- the Carbon APIs taking HFS+-style paths use colon-separated paths, relative paths begin with a colon, absolute paths begin with a volume name, two colons in a row is the equivalent of ..

For most purposes though, you won't want to use those APIs -- libc, Cocoa, BSD or CFURL-based APIs will be preferable. All of those expect POSIX-style /-separated paths.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Calculating relative transformations TomorrowPlusX 3 2,834 Jul 11, 2007 06:15 PM
Last Post: Skorche
  handle to char* LongJumper 1 3,012 May 18, 2005 11:09 PM
Last Post: LongJumper
  File Paths Nick 12 5,021 Mar 11, 2005 08:26 PM
Last Post: aaronsullivan