0000011111
0000011111

Reputation: 133

List files that don't have any extension using command `dir`

In a directory containing files with different extensions, e.g. .ext1, .ext2, and (no extension), how can I use the dircommand to list only the files that don't have any extension?

The command dir(fullfile('path/to/dir','*.ext1')) will list all .ext1 files, but I don't know of any option to read extension-less files.

Upvotes: 4

Views: 777

Answers (1)

Robert Seifert
Robert Seifert

Reputation: 25232

Try if the following fits all your needs:

allfiles = dir
filelist = {allfiles(3:end).name}

mask = cellfun(@isempty, regexp( filelist ,'[^\\]*(?=[.][a-zA-Z]+$)','match'))
output = filelist(mask)

The regular expression finds all filenames which have an extension and returns an empty array if not. Therefore cellfun(@isempty, ... ) will give you the desired mask.

Upvotes: 5

Related Questions