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

1 次查看(过去 30 天)
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.

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2020-5-26
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 '.'.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by