Clear Filters
Clear Filters

Problem with identification of strings

1 view (last 30 days)
Good Mornig,
could you find a solution for this: if I input:
files = dir(fullfile(open_folder, '*140821*.txt'));
it finds a structure array, anyway, if I try with:
b=strcat('*','140821','*')
files = dir(fullfile(open_folder, 'b.txt'));
It doesn't find any.
I would like to name a 'b' and than find the related file in the directory but that doesn't seem the right way!!
Could you help me?

Accepted Answer

Guillaume
Guillaume on 25 Feb 2015
Edited: Guillaume on 25 Feb 2015
files = dir(fullfile(open_folder, [b '.txt']));
or
files = dir(fullfile(open_folder, strcat(b, '.txt')));
or
files = dir(fullfile(open_folder, sprintf('%s.txt', b)));
The last one is my personal preference, and I would build b the same way:
b = sprintf('*%d*', 140821);
Note that in 'b.txt' the b is just the character 'b', there's no reason matlab would interpret it as the variable b.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!