comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: relative path from one absolute path to another?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: relative path from one absolute path to another? [message #49660 is a reply to message #49647] Tue, 08 August 2006 14:22 Go to previous messageGo to previous message
born.in.sssr@gmail.co is currently offline  born.in.sssr@gmail.co
Messages: 3
Registered: August 2006
Junior Member
Thank you all!
Here is my function, which is closer to greg michael idea but also uses
some interesting constructs from JD Smith:

;+
; NAME:
; FILE_RELPATH
; PURPOSE:
; Relative path from one absolute path to another
; CALLING SEQUENCE:
; rel_path = FILE_RELPATH(file, source_path)
; INPUTS:
; file, source_path: absolute path names
; if source_path is not given, then the current directory is
; taken as the source_path
; OUTPUTS:
; Relative path from source_path to file
; RESTRICTIONS:
; file and source_path should be reachable by file system
; MODIFICATION HISTORY:
; 08/2006 Maxim [Yossarian] Neumann
;-

function FILE_RELPATH, file, source
sep = path_sep()
if n_elements(source) eq 0 then source = '.'
to = strsplit(file_search(file, /FULLY_QUALIFY_PATH),sep,/EXTRACT)
from = strsplit(file_search(source,/FULLY_QUALIFY_PATH),sep,/EXTRAC T)
n_to = n_elements(to) & n_from = n_elements(from)
if n_from eq 1 && from[0] eq '' then n_from=0
ind = where(from ne to, cnt)
same = cnt eq 0 ? n_from<n_to : ind[0]
if same eq n_from then res = './' $
else res = strjoin(replicate('..'+sep,n_from-same))
if same ne n_to then res += strjoin(to[same:*],sep)
return, res
end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Interactive mode in IDL
Next Topic: Comparing Pixel Values in Images With IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 17:54:08 PDT 2025

Total time taken to generate the page: 1.19727 seconds