File Exchange

image thumbnail

relativepath.m

version 1.0.0.0 (2 KB) by Jochen Lenz
Convert path representations.

7 Downloads

Updated 18 Aug 2003

View License

RELATIVEPATH returns the relative path from an actual path to the target path.

Both arguments must be strings with absolute paths. The actual path is optional, if omitted the current dir is used instead. In case the volume drive letters don't match, an absolute path will be returned.

If a relative path is returned, it always starts with '.\' or '..\'

Syntax:
rel_path = RELATIVEPATH( target_path, actual_path )

Comments and Ratings (11)

Yul Kang

The following modification removes '\' at the end:

% Relative directory levels to target directory:
rel_path = fullfile(rel_path, tgt_path_cell{:});
% for i = 1 : length(tgt_path_cell)
% rel_path = [rel_path tgt_path_cell{i} filesep];
% end

Remy

M. Luppi

Igor

One more bug - this function alway adds "\" on to the end of the result:

relativepath( 'c:\temp\1.txt', 'C:\temp') = '.\1.txt\'

Igor

results in lowercase letters...

Lukas

David Zhang

works great on mac, does it also work on windows?

David Zhang

David Zhang

Ano Nymous

worked fine, good examples

Changshun Deng

very good! many thanks!

MATLAB Release Compatibility
Created with R12
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor