Parts of file name and path
[ returns the path name, file name, and
extension for the specified file. The file does not have to exist.
a character vector. The returned
ext field contains
a dot (
.) before the file extension.
Name of a file or folder, specified as a character vector.
Name of the file without any extension, specified as a character vector
File extension, specified as a character vector.
Return the different parts of a file specification to
ext. The full file specification is:
file = 'H:\user4\matlab\myfile.txt'; [pathstr,name,ext] = fileparts(file) pathstr = H:\user4\matlab name = myfile ext = .txt
Query parts of a user
[pathstr,name,ext] = fileparts('/home/jsmith/.cshrc') pathstr = /home/jsmith name = Empty matrix: 1-by-0 ext = .cshrc
filepartsinterprets the entire file name as an extension because it begins with a period.
The full or partial path to a destination folder location, always
the initial portion of
filename. Path names end
with a slash character and, where appropriate,
can begin with a drive letter. Windows® paths use backward slashes
\). UNIX® and Macintosh paths use forward
fileparts only parses file names.
It does not verify that a file or a folder exists.
You can reconstruct the file from the parts using:
On Microsoft® Windows systems,
you can use either forward (
/) or back (
slashes as path delimiters, even within the same file name. On UNIX and Macintosh systems,
/ as a delimiter. You can use the
to insert the correct separator character for the platform on which
your code executes:
sep = filesep; file = ['H:' sep 'user4' sep 'matlab' sep 'myfile.txt']; file = H:\user4\matlab\myfile.txt
If the input consists of a folder name only, be sure
that the right-most character is a delimiter (
the trailing portion of
filename as the name of
a file and returns it in
name instead of in
uigetfile to interactively select and
return a file name and path, or
interactively select and return a path name. If you call
the output of
can parse out the file name and extension.