Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

fullfile

Build full file name from parts

Syntax

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

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 seperator 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 seperator 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 or cell arrays of character vectors. Any nonscalar cell arrays must be of the same size.

Example: 'folder1'

Example: 'myfile.m, myfile2.m'

Example: {'folder1';'folder2'}

Data Types: char | cell

Output Arguments

collapse all

Full file specification, returned as a character vector or a cell array of character vectors.

Data Types: char | cell

More About

collapse all

Tips

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

Introduced before R2006a

Was this topic helpful?