fullfile

Returns a filename from dir1...dirN and filename fname.

Syntax

R = fullfile('dir1','dir2',....'dirN','fname')

Inputs

dir1,dirN,f
Zero, 1 or more directory names provided as components to a full pathname.
Type: string
fname
Filename with or without file extension. If fname is a cell, R will be a cell of file paths.
Type: cell | string

Outputs

R
Full path to the file(s) specified by the components provided.
Type: cell | string

Example:

Example including the fullfile function.
% create a pathname from drive, directories and filename.
pathname = fullfile('c:', 'tests', 'A', 'testscript.oml')

% nargout 0
fileparts(pathname)

% nargout 1 path 
R = fileparts(pathname)

% nargout 2 path and filename
[R1, R2] = fileparts(pathname)

% nargout 3 path, filename and file extension
[R1, R2, R3] = fileparts(pathname)

pathname = c:\tests\A\testscript.oml
ans = c:\tests\A
R = c:\tests\A
R1 = c:\tests\A
R2 = testscript
R1 = c:\tests\A
R2 = testscript
R3 = .oml
Example with multiple file names

R = fullfile('c:\\Program files', 'test', {'file1.txt', 'file2path/'})

R =
{
  [1,1] c:\Program files\test\file1.txt
  [1,2] c:\Program files\test\file2path\
}

Version History

2022.3