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

1 visualización (últimos 30 días)
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.

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 26 de Mayo de 2020
Editada: MathWorks Support Team el 26 de Mayo de 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 '.'.

Más respuestas (0)

Categorías

Más información sobre Search Path en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by