I would create a function that parses the filenames and split them into variables of a table (or even a timetable). Then it's trivial to use matlab comparison functions to get the relevant rows of the table:
function filedetails = getdetails(filelist)
filenames = vertcat(filelist.name);
assert(size(filenames, 2) == 11, 'Length of file names not consistent with pattern')
Location = string(filenames(:, 1:3));
Type = string(filenames(:, 4:7));
Date = datetime(filenames(:, 8:11), 'InputFormat', 'MMyy');
Filename = string({filelist.name}');
filedetails = table(Location, Type, Date, Filename);
end
Now it's easy to filter the table according to whichever pattern you want:
filelist = dir('C:\somewhere\*.txt');
filedetails = getdetails(filelist);
selectedfiles = filedetails.Filename(filedetails.Location == 'XYZ');
selectedfiles = filedetails.Filename(ismember(filedetails.Location, {'XYZ', 'UVW'});
selectedfiles = filedetails.Filename(filedetails.Location == 'XYZ' | filedetails.Location == 'UVW');
selectedfiles = filedetails.Filename(filedetails.Type == 'ABCD' & filedetails.Location == 'XYZ');
selectediles = filedetails.Filename(isbetween(filedetails.Date, datetime(2018, 1, 1), datetime(2018, 3, 31)));
Note the use of isbetween to get files between a date range.
Best Answer