Path Manipulation Functions
File path splitting into directory, filename and extension.
(dir, filename, ext) = fileparts(path)
fileparts(path) splits string path into the directory (initial part until the last file separator), the filename without extension (substring after the last file separator before the last dot), and the extension (substring starting from the last dot after the last file separator).
The directory is empty if path does not contain any file separator, and the extension is empty if the remaining substring does not contain a dot. When these three strings are concatenated, the result is always equal to the initial path.
The separator depends on the operating system: a slash on unix (including Mac OS X and Linux), and a backslash or a slash on Windows.
(dir, filename, ext) = fileparts('/home/tom/report.txt') dir = /home/tom/ filename = report ext = .txt (dir, filename, ext) = fileparts('/home/tom/') dir = /home/tom/ filename = '' ext = '' (dir, filename, ext) = fileparts('results.txt.back') dir = '' filename = results.txt ext = .back
File path separator.
ch = filesep
filesep gives the character used as separator between directories and files in paths. It depends on the operating system: a slash on unix (including Mac OS X and Linux), and a backslash on Windows.
File path construction.
path = fullfile(p1, p2, ...)
fullfile constructs a file path by concatenating all its string arguments, removing separators when missing. At least one input argument is required.
fullfile('/home/tom/', 'report.txt') /home/tom/report.txt fullfile('/home/tom', 'data', 'meas1.csv') /home/tom/data/meas1.csv