fullfile

Builds a file path from folder and file name parts.

Category: Programming > Files and Folders

Syntax

f = fullfile(part1, ..., partN)

Joins the parts with the platform separator.

Description

fullfile inserts exactly one separator between parts and removes the doubled ones that appear when a part already ends or starts with a separator, so fullfile('a/', '/b') is a\b on Windows. Empty parts are skipped.

It does not check that the path exists, and it does not resolve '..'. If one argument is a cell array, the other parts are combined with each of its elements in turn.

Input arguments

part
Text pieces: folders and a final file name. A cell array in one argument produces a cell array of paths.

Output arguments

f
The joined path, of the same kind as the inputs.

Example

Joining and the cell form

fullfile('data', 'run1', 'out.csv')
fullfile('a/', '/b')
fullfile({'a', 'b'}, 'x.m')
Output
ans = 'data\run1\out.csv'
ans = 'a\b'
ans = 1×2 cell

    {'a\x.m'}    {'b\x.m'}

See also

fileparts filesep pathsep exist