| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
[pathstr, name, ext, versn] = fileparts(filename)
[pathstr, name, ext, versn] = fileparts(filename) returns the path name, file name, extension, and version for the specified file. filename is a string enclosed in single quotes. The returned ext field contains a dot (.) before the file extension.
The fileparts function is platform dependent.
You can reconstruct the file from the parts using
fullfile(pathstr,[name ext versn])
Return the pieces of a file specification string to the separate string outputs pathstr, name, ext, and versn. The full file specification is
file = '\home\user4\matlab\classpath.txt';
The character used to separate the segments of a path name is dependent on the operating system you are currently running on. In this example, it is the backslash (\) character, which is used as a separator on Microsoft Windows platforms. Use the filesep function to insert the correct separator character:
sep = filesep;
file = ['' sep 'home' sep 'user4' sep 'matlab' sep ...
'classpath.txt' ''];
Use fileparts to return the path name, file name, user name, and file version, if there is one:
[pathstr, name, ext, versn] = fileparts(file)
pathstr =
\home\user4\matlab
name =
classpath
ext =
.txt
versn =
''On Windows platforms, C:\ and C: are two distinct entities, where C:\ (with backslash) is the C drive in your computer, and C: (without backslash) represents the current working directory.
fullfile, ver, verLessThan, version
![]() | filemarker | fileread | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |