cleanpath(path_name​, working_path)

Clean file path names removing redundant characters as well as circular paths
48 Downloads
Updated 21 Oct 2016

View License

Removes redundant characters from the file path name, e.g. '//', '/./' as well as initial './' and circular paths e.g. 'abc/def/../def/'.
Additionally, all file separators are set to the platform file separator.

If a working directory path is given (the pwd function can be used to get the current directory), the input path name is assumed to be an absolute path and the working directory path is removed thus returning the relative path.

Cite As

Marco Bucci (2026). cleanpath(path_name, working_path) (https://www.mathworks.com/matlabcentral/fileexchange/59771-cleanpath-path_name-working_path), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on File Operations in Help Center and MATLAB Answers
Version Published Release Notes
1.2.0.0

The internal RELATIVEPATH function should now working correctly. I can remove totally as well as partially the working directory path from the absolute path.

1.1.0.0

Bug fixing: the internal relpath function was missed
previous upload failed

1.0.0.0