Why does FILEPARTS interpret UNIX hidden files as an extension with no basename?

2 views (last 30 days)
I would like FILEPARTS to interpret UNIX hidden files such as .bashrc as a basename with no extension, rather than the default extension with no basename.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 26 May 2020
Edited: MathWorks Support Team on 26 May 2020
FILEPARTS is intended primarily for use following checks for attributes, such as FILEATTRIB. For example:
[stat,mess] = fileattrib(filename);
if mess.directory
% Process as directory
else
% Process as file using FILEPARTS to determine extension
[pathstr, name, ext, versn] = fileparts(filename);
end
In the case of hidden UNIX files, FILEPARTS has been designed to give the same results as common filename-splitting functions in other languages. In particular, the Microsoft Visual C/C++ function _splitpath() interprets .bashrc as a file with null basename and extension '.bashrc'.
To reinterpret this as a basename with no extension, you can check for null basenames:
[pathstr, name, ext, versn] = fileparts(filename);
if isempty(name) && ~isempty(ext)
name = ext;
ext = '';
end
The behavior on hidden directories is consistent with the overall intent. File a.b.c should report basename a.b and extension .c; the rules to give this behavior also split parent directory '..' as name '.' and extension '.'.

More Answers (0)

Categories

Find more on Search Path in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!