Effacer les filtres
Effacer les filtres

issues of Sensitive in 'dir' function

22 vues (au cours des 30 derniers jours)
Qingping
Qingping le 28 Jan 2013
Modifié(e) : Jan le 9 Oct 2015
There is a file named abc.m, but I'm not sure the name is abc.m or Abc.m.
How to determine the true name of file?
I have a test with the true name of file is abc.m
a=dir('abc.m') %a.name=abc.m
and
b=dir('Abc.m') %b.name=Abc.m,
So, I don't know how to deal this question.
  1 commentaire
Walter Roberson
Walter Roberson le 28 Jan 2013
Is your filesystem case sensitive?

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 28 Jan 2013
Modifié(e) : Jan le 9 Oct 2015
d = dir('*.m');
match = strcmpi({d.name}, 'abc.m'); % [EDITED] strcmp*i*
Name = d(match).name;
Another implementation: FEX: FileRealCase. This adjusts the upper/lower case of the path also.
  1 commentaire
Paul Martin
Paul Martin le 9 Oct 2015
I think the correct function is case-insensitive string comparison with strcmpi:
match = strcmpi({d.name}, 'abc.m')

Connectez-vous pour commenter.

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 28 Jan 2013
Modifié(e) : Azzi Abdelmalek le 28 Jan 2013
d=dir('*.m');
f1=char(d.name);
f=upper(f1);
idx=find(cellfun(@(x) isequal(x,upper('Abc.m')),cellstr(f)));
out=f1(idx,:)
  1 commentaire
Jan
Jan le 28 Jan 2013
There is no reason to convert the names into a CHAR matrix f1. Instead of ISEQUAL inside a CELLFUN, STRCMPI compares directly.

Connectez-vous pour commenter.

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by