Home Ask Login Register

Developers Planet

Your answer is one click away!

boethian February 2016

Exclude / negate word in filenames using FilterSpec in uigetfile

I would like to open a dialog box to select a file and show all files with a certain extension, but exclude certain filenames based on pattern match (regex or otherwise).

For example, I want to show CSV files, but not ones that have 'abc' in their filename.

To show ALL .csv files I can do (NOT what I want):

[filename, pathname] = uigetfile({'*.csv', 'CSV Files (*.csv)'});

With regular expressions, I can successfully exclude filenames with 'abc' as follows (thanks to How to negate specific word in regex?):

filenames = {'myfile.csv'; 'myfile-abc.csv'}
regexp(filenames, '^(?!.*abc).*.csv')

However, the following does not work:

[filename, pathname] = uigetfile({'^(?!.*abc).*.csv', 'CSV Files (*.csv)'});

How can I negate a word from occuring in the filename? It seems I can only do positive wildcards (*) but not negation.


Sebastian February 2016

No it seems to be impossible. If you look into the implementation in Matlab, you will find that the Java standard dialog is called. Either you develop your own dialog or you check later the outputs of the dialog.

Post Status

Asked in February 2016
Viewed 3,238 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life