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

Réponses (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
Walter Roberson
Walter Roberson le 28 Sep 2017

0 votes

I would recommend loading in all of the file names first, and then doing appropriate string searches, using regexp() or strfind() or contains()

Catégories

En savoir plus sur File Operations dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by