0

I want to exclude a set of file extensions and otherwise list folder contents.

%get filenames in current directory
p = dir(pwd);
p = {p.name};
p = p(1:min(end,20))'
%construct regular expression
%exclude = {'ini','m'}; %just for your convenience
reg = '\.(^ini|m)$'; 

%actually print file names/paths of files without a certain extension
regexpi(p,reg,'match','once')

This, however, does not work. How can I get the files that exclude these file extensions (last X amount of characters in path)? I tried [^abc] but this excludes individual characters, which I don't want. Please use regexp or regexprep in your answer

user2305193
  • 2,079
  • 18
  • 39

1 Answers1

0

You wrote:

reg = '\.(^ini|m)$';

The ^ caret anchor comes after a . dot, so it will never match start-of-string. Remove it FTW:

reg = '\.(ini|m)$'; 
MrBill
  • 89
  • 4