Using struct=dir(selpath), what do '.' and '..' mean as struct.name?
12 ビュー (過去 30 日間)
古いコメントを表示
Zeynab Mousavikhamene
2019 年 10 月 9 日
回答済み: Walter Roberson
2019 年 10 月 10 日
When I use struct=dir(selpath) and then struct.name, I see two extra names ('.' and '..' ) that are not name of folders in the route.
0 件のコメント
採用された回答
Walter Roberson
2019 年 10 月 10 日
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]) = []; %get rid of all folders
or
dinfo = dir(selpath);
dinfo(ismember({dinfo.name}, {'.', '..'})) = []; %get rid of those ones
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.
Linux does not define a sort order, and I find postings that say that in practice the order can vary between different machines. I see one posting saying that etx4 filesystems end up sorting files according to a hash of their name. https://serverfault.com/questions/406229/ensuring-a-repeatable-directory-ordering-in-linux
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 .
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!