フィルターのクリア

Search folders/paths with strfind: how to do excluding search?

3 ビュー (過去 30 日間)
Felix
Felix 2012 年 10 月 25 日
With the code below (adapted from an old question here) I create a list of all folders and subfolders within a give path (using the command genpath and strtok). Using strfind I then select only those folders that contain a given keyword. However, strfind only allows inclusive search, but how can I make e.g. condition 3 such that it only selects the paths that DONT contain the keyword?
listOfFolderNames = {};
allfolders=genpath('D:\test\');
while true
[singleSubFolder, allfolders] = strtok(allfolders, ';');
if isempty(singleSubFolder), break; end
listOfFolderNames = [listOfFolderNames singleSubFolder];
end
indices=strfind(listOfFolderNames,'word a); % <-- filter condition 1
Index = find(not(cellfun('isempty', indices)));
foldersa=listOfFolderNames(Index);
indices2=strfind(foldersa,'word b'); % <-- filter condition 2
Index2 = find(not(cellfun('isempty', indices2)));
foldersb=foldersa(Index2);
indices3=strfind(foldersb,'word c'); % <-- filter condition 3. How to make this eclusive??
Index3 = find(not(cellfun('isempty', indices3)));
foldersfinal=foldersb(Index3);

採用された回答

Matt Fig
Matt Fig 2012 年 10 月 25 日
You could just leave out the call to NOT in Index3.
  1 件のコメント
Felix
Felix 2012 年 10 月 25 日
-_- lets quickly forget about this question...

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by