List all files in a directory given a regular expression / a set of extensions (Matlab)

后端 未结 3 1457
花落未央
花落未央 2020-12-06 07:28

I have a regular expression defining the filenames of interest. What is the best way to list all files in a directory that match this condition?

My attempt at this i

3条回答
  •  醉话见心
    2020-12-06 08:07

    Suppose you have a cell array with possible extensions, e.g., exts = {'avi','mp4'}. Then you can do the following

    f = cellfun( @(x) dir( fullfile( DIR, ['*.',x] ) ), exts, 'UniformOuput', false ); 
    result = [f{:}];
    

提交回复
热议问题