• 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
Best way to build relative pathname?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Best way to build relative pathname?


  • Subject: Best way to build relative pathname?
  • From: "M. Uli Kusterer" <email@hidden>
  • Date: Sun, 11 May 2003 23:48:40 +0200

Hi,

I need to build relative pathnames to files. I have the pathname to a folder, and I have the full path to the file (NSStrings). I also need to be able to keep any absolute pathnames that can't be expressed relative to the folder path. What's the best way to do that in Cocoa?

1) I tried to make an NSURL object, but obviously the baseURL stuff is intended to generate a complete URL from a relative one and the folder's URL, not the other way round :-(

2) I could simply do straight string manipulation, checking whether the two strings start with the same character sequence, and deleting everything up to that point. But I'm afraid I may make some mistakes, so I'd rather use an existing routine. E.g. I'll have to make sure the folder path ends in a slash, because otherwise these two paths would be resolved wrongly against each other:

/Users/foo/folder
/Users/foo/folder manager/file.txt
= " manager/file.txt" ... Ouch!

I'm sure there are more pitfalls like these, so if the code already exists, I'd like to avoid rolling my own.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Prev by Date: NSTextStorage: efficient way to find a specific attribute?
  • Next by Date: The best way to archive dependancies
  • Previous by thread: Re: NSTextStorage: efficient way to find a specific attribute?
  • Next by thread: Re: Best way to build relative pathname?
  • Index(es):
    • Date
    • Thread