It is not recommended to skip the first two entries because there are real cases where . and .. will not be the first two entries.
Instead:
dinfo = dir(selpath);
dinfo([dinfo.isdir]) = [];
or
dinfo = dir(selpath);
dinfo(ismember({dinfo.name}, {'.', '..'})) = [];
Amplification: MS Windows and Unix systems do not define a particular sort order for files returned by directory services. The order is defined by the file system driver, and historically has included "write a new file in the first available slot" unsorted. Microsoft's NTFS file system does not appear to have a publicly defined file order, but in practice appears to sort by byte value. Or perhaps it sorts by UTF-16 code point... I do not know.
MacOS's HFS+ filesystem uses 16 bit UNICODE characters "fully decomposed and in canonical order" -- but the canonical order is apparently not the right canonical order, and people who work with file internationalization apparently get pretty frustrated about HFS+ in practice.
The practical upshot for NTFS (Windows) and HFS+ (Mac) is that file names that begin with any of the characters !"#$%&'()*+,- or space usually sort before '.' in dir() order .
Best Answer