Code covered by the BSD License  

Highlights from
Relative Filename

4.0

4.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 4.39 KB File ID: #25701

Relative Filename

by Kesh Ikuma

 

31 Oct 2009 (Updated 19 Jan 2011)

A pair of M-files to convert between full and relative filenames.

| Watch this File

File Information
Description

RELFILE(FILE,PATH) converts full filename FILE to a relative filename with respect to PATH.

REL2FULLFILE(RELFILE,PATH) converts relative filename RELFILE to full filename using PATH as the base path.

Examples:

relfile('C:\Program Files\MATLAB\R2009a\bin\matlab.exe','C:\Program Files\MATLAB\R2009a')

returns '.\bin\matlab.exe' and

rel2fullfile('.\bin\matlab.exe','C:\Program Files\MATLAB\R2009a')

gets the original path back.

relfile('C:\Program Files\MATLAB\R2009a\bin\matlab.exe','C:\Program Files\MATLAB\R2009a\toolbox\matlab')

returns '..\..\bin\matlab.exe' and

rel2fullfile('..\..\bin\matlab.exe','C:\MATLAB\toolbox\matlab')

expands to 'C:\MATLAB\bin\matlab.exe'

Note on OS Compatibility:
Although these functions are written to be OS independent, they have been only tested under Windows. Please report here if you successfully used these functions under Linux or Mac.

MATLAB release MATLAB 7.10 (2010a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
26 Jan 2011 Tal Kenig

Works fine on Linux.
Note that it works wrong if the 2nd input contains /..
Overall very handy.

Please login to add a comment or rating.
Updates
19 Jan 2011

Added support for FILE given as a cellstr array, allowing multiple conversions with 1 call

Tag Activity for this File
Tag Applied By Date/Time
file Kesh Ikuma 02 Nov 2009 10:16:35
path Kesh Ikuma 02 Nov 2009 10:16:35
utility Kesh Ikuma 02 Nov 2009 10:16:35
relative filename Kesh Ikuma 04 Nov 2009 11:18:46
partial filename Kesh Ikuma 04 Nov 2009 11:18:54

Contact us at files@mathworks.com