File Path relative to current file

rhale1

KU Mac Geek
Looking at all of the path documentation, this seems possible. I want to get a file's path (I do this with an open panel) relative to the current file/directory. That is, if I have a file called myself.file and want to find the path of additionalfile.file in relation to myself.file (so that I don't get things like /users/os_user/Documents/whatever or /Library/WebServer/Documents). How exactly would I do this in Cocoa? I can get the full path, but this isn't what I need. Any ideas?
 
Hmm...you can get the entire contents of a certain directory, then go through that for the file you need (contents are in an array).

[[NSFileManager defaultManager]directoryContentsAtPath:path]
 
I think a clearer example may be warranted here. Do you mean that if you have:

/foo/bar/myfile.file

and

/foo/baz/otherfile.file

that you want to figure out that the relative path to otherfile.file (in relation to myfile.file) is:

../baz/otherfile.file

Is this what you're trying to calculate?
 
Yes, it is. I got a hit from Cocoa-Dev, by John Anderson. I'll post it here incase anyone else wants this help.

Now I am trying to get an NSPopUpButton menu to be populated from an array. That is, I want an NSMenuItem to correspond to a record in my Array (stored via NSUserDefaults), so that if my array has values Ryan, Josh, Joe, Lisa for key "UserName" in an Array, I want the menu to show all of the values as seperate menu items.
 
Originally posted by rhale1
Yes, it is. I got a hit from Cocoa-Dev, by John Anderson. I'll post it here incase anyone else wants this help.
...

Is there actually some Cocoa calls that do this for you? I assumed that you would just parse the respective path strings to get what you wanted?

Sorry, can't help on your other question.
 
OK, so it is just some code to do it. I was going to be really impressed if someone had taken the time to actually make this a part of the os api. Thanks for posting it.
 
Back
Top