Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

fullfile

Build full file name from parts

Syntax

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

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: 'folder1'

Example: 'myfile.m, myfile2.m'

Example: {'folder1';'folder2'}

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.

Introduced before R2006a

Was this topic helpful?