| MATLAB Function Reference | ![]() |
[pathstr, name, ext, versn] = fileparts(filename)
[pathstr, name, ext, versn] = fileparts(filename) returns the path, filename, 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';
Note that the character used to separate the segments of a pathname 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 Windows® systems. You can use the filesep function as shown below to insert the correct separator character:
sep = filesep;
file = ['' sep 'home' sep 'user4' sep 'matlab' sep ...
'classpath.txt' ''];
Now use fileparts to return the path, filename, user name, and file version, if there is one:
[pathstr, name, ext, versn] = fileparts(file)
pathstr =
\home\user4\matlab
name =
classpath
ext =
.txt
versn =
''![]() | filemarker | filehandle | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |