Finding files WITHOUT a specfic prefix (or suffix, extension, etc.) using dir
조회 수: 22 (최근 30일)
이전 댓글 표시
Hello all, I have a question partly inspired by the question here, which asks how to find a file with a known prefix. Now, what if I want to suppress a specific prefix, but not use more complicated strfind (although I could use startsWith) operation using the 'dir' command. The obvious example is avoiding all files starting with a period: '.example.txt'.
Is there a simple way to suppress certain prefixes using 'dir'? How about suppressing suffixes or extensions (rather than exhaustively looking for the extensions you do want)?
댓글 수: 0
채택된 답변
Guillaume
2018년 7월 3일
No, the filtering capabilities offered by dir are fairly limited. If you want to exclude some pattern, you'll have to get the whole list then use string search functions such as startsWith you've mentioned or regexp. It's only one more line of code so shouldn't be any issue.
e.g. to remove all files starting with .
filelist = dir;
filelist = filelist(~startsWith({filelist.name}, '.''));
댓글 수: 1
Bram ter Huurne
2024년 9월 6일
"so should'nt be any issue" is usually not related to the code but more on performance. I would like to exclude a folder that contains 100k+ files, which is now made exceedingly difficult, except to change the directory structure.
추가 답변 (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!