Extract files of specific extension from already searched folder

1 view (last 30 days)
Myfolder contains various filetypes (various extensions). File search step is completed with
Myfolder=dir('*.*')
Instead of repeated search with 'dir' command for each filetype, is it possible to extract filenames from 'Myfolder'(already searched) based on extensions like *.xlsx, *.fig, *.bmp?

Accepted Answer

Stephen23
Stephen23 on 10 Oct 2019
Edited: Stephen23 on 10 Oct 2019
>> S = dir('*.*');
>> S.name
ans = .
ans = ..
ans = archive
ans = iregexp.m
ans = iregexp.png
ans = iregexp.zip
ans = iregexp_doc.m
ans = iregexp_zip.m
>> [~,~,E] = cellfun(@fileparts,{S.name},'uni',0);
>> X = strcmpi(E,'.m');
>> T = S(X);
>> T.name
ans = iregexp.m
ans = iregexp_doc.m
ans = iregexp_zip.m

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!