Find files according to a pattern that are on the Matlab path?
Show older comments
Let's say I have 2 folders of generated code. One is on my Matlab path, and one is not. I would like to find all C header files that end in a number between 1 and 3 that are on the path. What is the best way of doing this? I feel like what I have below is clunky.

folder = 'C:\code';
found_files = dir([folder filesep '**' filesep '*.h']); % Finds all 10 files
within_range_idx = ~cellfun(@isempty, (regexp({found_files.name}, '[1-3]\.h$')));
found_files = found_files(within_range_idx);
pathCell = regexp(path, pathsep, 'split');
found_files = found_files(contains({found_files.folder}, pathCell)):
Accepted Answer
More Answers (0)
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!