PDA

View Full Version : how does Mac OS X handle relative file paths?


WhatMeWorry
2005.08.08, 09:26 PM
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.

unknown
2005.08.08, 10:44 PM
I do

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/GridGridGridGridSource.tgz

WhatMeWorry
2005.08.08, 10:53 PM
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.

ThemsAllTook
2005.08.09, 02:46 AM
#include <Carbon/Carbon.h>
#include <limits.h>

CFURLRef bundleURL;
UInt8 bundlePath[PATH_MAX];

bundleURL = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFURLGetFileSystemRepresentation(bundleURL, 1, bundlePath, PATH_MAX);
CFRelease(bundleURL);

Zekaric
2005.08.18, 07:48 PM
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.

Duane
2005.08.18, 07:52 PM
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 :

Zekaric
2005.08.18, 08:08 PM
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.

OneSadCookie
2005.08.18, 08:09 PM
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.