フィルターのクリア

How to search pathname for string

1 回表示 (過去 30 日間)
Aadil
Aadil 2012 年 8 月 22 日
Hi,
I'm using this code to give the filepath of the selected file:
[FileName,PathName,FilterIndex] = uigetfile
PathName = T:\Field Test\Field Test Scripts\Master Files\For Single Screen File\Final Combined Script\OLD\
Now I want to search this pathname for 'OLD', so I used this code:
strcmpi(PathName, 'OLD')
But it always returns false:
ans =
0
What am I doing wrong?
Thanks,

採用された回答

José-Luis
José-Luis 2012 年 8 月 22 日
編集済み: José-Luis 2012 年 8 月 22 日
You are comparing two strings for equality, and the comparison is not case sensitive (help strcmpi). What you wanted to do, I guess, is to find out if a string is included in another string. For that i would recommend:
isFound = ~isempty(regexp(Pathname,'OLD'));
Cheers!
  3 件のコメント
José-Luis
José-Luis 2012 年 8 月 22 日
My pleasure!
Jan
Jan 2012 年 8 月 22 日
Faster:
isFound = strfind(Pathname, 'OLD')
Safer:
isFound = strfind(fullfile(Pathname, filesep), [filesep, 'OLD', filesep])
This avoids a false match for "C:\Temp\REINHOLD\newData\".

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by