Reputation: 223
I am trying to find a list of jpg files but also using filesep (to break the names of the files) in one line
dir([folder,[filesep '*.' 'jpg']]).
The above command works for me. But I also want to find the files that include in their name a specific word like 'blue' but when I tried to use
dir([folder,[filesep '*.' '*blue*jpg']])
it did not work, the program does not find any files at all. Is there anyway to do this in one line? Thank you.
Upvotes: 0
Views: 336
Reputation: 114976
Why don't you use fullfile
? This command will take care of the filesep
for you in a much nicer way:
dir( fullfile( folder, '*blue*.jpg' ) );
Upvotes: 3
Reputation: 5821
You want to use dir([folder,[filesep '*blue*.jpg']])
, or more simply dir([folder filesep '*blue*.jpg'])
.
Just to be clear, the *
character acts as a "wildcard". It can represent zero or more characters of any kind.
*.jpg
finds all .jpg files because *
allows the filename before the extension to be anything.
red*.jpg
finds all .jpg files starting with red
, like redhouse.jpg
or redflower.jpg
.
*green.jpg
finds all .jpg files ending with green
, like grassgreen.jpg
or darkgreen.jpg
*blue*.jpg
finds all .jpg files that contain the word blue
, like skyblue.jpg
, bluecar.jpg
, or mybluebox.jpg
.
What you're using now, dir([folder,[filesep '*.' '*blue*jpg']])
would find files like something.BLAHblueBLEHjpg
.
Upvotes: 1