fullfile

Build full file name from parts

Syntax

  • f = fullfile(filepart1,...,filepartN) example

Description

example

f = fullfile(filepart1,...,filepartN) builds a full file specification, f, from the folders and file names specified. fullfile inserts platform-dependent file separators where necessary, and does not add a trailing file separator. The output of fullfile is conceptually equivalent to

f = [filepart1 filesep filepart2 filesep ... filesep filepartN]

Examples

expand all

Create a Full File Name

f = fullfile('myfolder','mysubfolder','myfile.m')
f =
myfolder\mysubfolder\myfile.m

fullfile returns a string containing the full path to the file. On Windows® platforms, the file separator character is a backslash, \. On other platforms, the file separator might be a different character.

Create Paths to Multiple Files

f = fullfile(toolboxdir('matlab'),'iofun',{'filesep.m';'fullfile.m'});

fullfile returns a cell array containing a path to the file filesep.m, and a path to the file fullfile.m.

Create a Path to a Folder

f = fullfile(matlabroot,'toolbox','matlab',filesep);

fullfile does not trim a leading or trailing filesep.

Input Arguments

expand all

filepart1,...,filepartN — Folder and file namesstrings | cell arrays of strings

Folder and file names, specified as strings and cell arrays of strings. Any nonscalar cell arrays must be of the same size.

Example: 'folder1','folder2','myfile.m'

Example: {'folder1';'folder2'},{'subfolder1';'subfolder2'},'myfile.m'

Was this topic helpful?