LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-31-2009, 06:56 PM   #1
abk4523
Member
 
Registered: Jun 2004
Distribution: RH8/Fedora Core 4
Posts: 139

Rep: Reputation: 15
linux equivalent to pathrelativepathto?


I'm not sure I'm in the right forum. While at another site, I found a thread asking for a linux equivalent to pathrelativepathto. Anyone know it off the top of thier heads? 10q.

Last edited by abk4523; 10-31-2009 at 06:57 PM. Reason: typos
 
Old 10-31-2009, 08:01 PM   #2
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 443
Blog Entries: 1

Rep: Reputation: 48
Ok, as I understand it, 'pathrelativepath()' takes two directories as arguments, and returns the path of the second directory, as a path relative to the first.

In other words

Code:
pathrelativepath( "/home/bartonski/bin", "/home/bartonski/texts/novel");
should return "../texts/novel".

I don't know of any such function off hand, but rolling your own should be fairly trivial:

Step 1: Express both directories as absolute paths.

Step 2: remove the parts of the paths that are the same:

Code:
/home/bartonski/bin
/home/bartonski/texts/novel
Step 3: For each level in the first directory, prepend "../" to the second.

Code:
bin
../texts/novel
That, plus some error handling ought to get you where you need to go.

What language are you trying to write in?

Last edited by bartonski; 10-31-2009 at 08:08 PM.
 
Old 10-31-2009, 08:08 PM   #3
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 10-31-2009, 08:21 PM   #4
reickler
LQ Newbie
 
Registered: Sep 2009
Posts: 29

Rep: Reputation: 20
I don't know of any native linux commands that would do what you need, but I would image you can do it with perl. At quick glace, something like the 'abs2rel' in the 'File::Spec' module might work with a little creativity.
 
Old 10-31-2009, 08:21 PM   #5
abk4523
Member
 
Registered: Jun 2004
Distribution: RH8/Fedora Core 4
Posts: 139

Original Poster
Rep: Reputation: 15
Thanks for the reply. I'm not sure which language he is using but I passed the solution.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
A linux equivalent to Locate32? spacejesus Linux - Software 5 12-13-2009 02:07 PM
Linux equivalent of COM? mrtedweb Programming 17 05-19-2009 01:59 PM
linux equivalent of torr raphtor Linux - Newbie 2 09-11-2008 05:26 PM
altzone equivalent in Linux ? sangeeta Linux - Software 1 11-03-2007 08:18 AM
Snagit Linux equivalent jdestruel Linux - Software 1 05-08-2007 01:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration