Searching for a file containing certain words

Hi,
Want to search for a file that has word1, word2 and word3 in the file name. I realize I can do this by using File=dir('* word1 * * word2 * * word3 *') However, I would like to be able to loop over different values of each word to select different files.
For example I want to find files containing the following words from many files:
A, 1, top
B, 1, top
C, 1, top
I thought I could make word1 into an array containing A, B and C but then I cannot use the dir statement above. Any suggestions would be appreciated. Many Thanks

Answers (2)

How about the following code?
word1 = {'A','B','C'};
for kk = 1:numel(word1)
str = ['*',word1{kk},'*1*top*'];
File=dir(str);
% Some process here
...
end
I would recommend loading in all of the file names first, and then doing appropriate string searches, using regexp() or strfind() or contains()

Categories

Asked:

on 25 Sep 2017

Answered:

on 28 Sep 2017

Community Treasure Hunt

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

Start Hunting!