Why does FILEPARTS interpret UNIX hidden files as an extension with no basename?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 27 Juin 2009
Modifié(e) : MathWorks Support Team
le 26 Mai 2020
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.
Réponse acceptée
MathWorks Support Team
le 26 Mai 2020
Modifié(e) : MathWorks Support Team
le 26 Mai 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 '.'.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Search Path dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!