Reputation: 133
In a directory containing files with different extensions, e.g. .ext1
, .ext2
, and (no extension), how can I use the
dir
command 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
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