필터 지우기
필터 지우기

issues of Sensitive in 'dir' function

조회 수: 22 (최근 30일)
Qingping
Qingping 2013년 1월 28일
편집: Jan 2015년 10월 9일
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
Walter Roberson
Walter Roberson 2013년 1월 28일
Is your filesystem case sensitive?

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2013년 1월 28일
편집: Jan 2015년 10월 9일
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
Paul Martin
Paul Martin 2015년 10월 9일
I think the correct function is case-insensitive string comparison with strcmpi:
match = strcmpi({d.name}, 'abc.m')

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 28일
편집: Azzi Abdelmalek 2013년 1월 28일
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
Jan
Jan 2013년 1월 28일
There is no reason to convert the names into a CHAR matrix f1. Instead of ISEQUAL inside a CELLFUN, STRCMPI compares directly.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by