Main Content

fullfile

Build full file name from parts

Description

example

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.

Examples

collapse all

fullfile returns a character vector containing the full path to the file. On Windows® platforms, the file separator character is a backslash (\).

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

    'myfolder\mysubfolder\myfile.m'

fullfile returns a character vector containing the full path to the file. On UNIX® platforms, the file separator character is a forward slash (/).

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

fullfile returns a cell array containing paths to the files myfile1.m and myfile2.m.

f = fullfile('c:\','myfiles','matlab',{'myfile1.m';'myfile2.m'})
f =

  2×1 cell array

    'c:\myfiles\matlab\myfile1.m'
    'c:\myfiles\matlab\myfile2.m'

Create paths to folders using file separators and dot symbols.

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.

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

c:\folder1\folder2\..\folder3\.

Input Arguments

collapse all

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

Example: fullfile('c:\','user','docs')

Example: fullfile('\\','Server01','user','docs')

Example: fullfile('home','users','docs',{'myfile.m', 'myfile2.m'})

Data Types: char | cell | string

Output Arguments

collapse all

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.

Data Types: char | cell | string

Tips

  • To split a full file name into folder parts, use the split function.

Extended Capabilities

Version History

Introduced before R2006a