fullfile

Syntax

Description

f = fullfile(filepart1,...,filepartN) builds
a full file specification from the specified folder and file names. fullfile inserts
platform-dependent file separators where necessary, but does not add
a trailing file separator. On Windows® platforms, the file separator
character is a backslash (\). On
other platforms, the file separator might be a different character.

fullfile replaces all forward slashes (/)
with backslashes (\) on Windows. On UNIX® platforms,
the backlash (\) character is a valid character
in file names and is not replaced.

fullfile does not trim leading or trailing
separators. fullfile collapses inner repeated file
separators unless they appear at the beginning of the full file specification. fullfile also
collapses relative directories indicated by the dot symbol, unless
they appear at the end of the full file specification. Relative directories
indicated by the double-dot symbol are not collapsed.

Collapse File Separators and Dot Symbols on Windows

fullfile does not trim leading or trailing file separators. filesep returns the platform-specific file separator character.

f = fullfile('c:\','myfiles','matlab',filesep)

f =
c:\myfiles\matlab\

fullfile collapses repeated file separators unless they appear at the beginning of the full file specification.

f = fullfile('c:\folder1', '\\\folder2\\')

f =
c:\folder1\folder2\

fullfile collapses relative directories indicated by the dot symbol unless they appear at the end of the full file specification. Relative directories indicated by the double-dot symbol are not collapsed.

Output Arguments

Full file specification, returned as a character array, a string array, or a cell array of
character vectors. If any input argument is a string array,
f is a string array. Otherwise, if any input argument
is a cell array of character vectors, f is a cell array
of character vectors. Otherwise, f is a character
array.