How to exclude specific results from dir

118 ビュー (過去 30 日間)
Bob Thompson
Bob Thompson 2021 年 11 月 18 日
回答済み: Stephen23 2021 年 11 月 18 日
I have a series of folders:
S1
A1
A1b1
A1b2
A1b1_test
A2
A2b1
A2b2
A2b3_test
...
I have written a script to collect the different levels and their contents for processing, but I have having a difficult time removing the _test folders. Is there any simple way I can exclude the folders with the _test suffix (_test will be a constant suffix)? If I absolutely have to I can loop through, determine the number following A and b and do something like the following, but it is not preferred:
A1 = dir('A*');
A1 = A1(~ismember({A1.name},{'.','..'}));
% Preferred method, if possible
A1 = A1(~ismember({A1.name},{'*_test'}));
% If absolutely necessary
*detect appropriate A#b# configuration*
A1 = A1(~ismember({A1.name},{sprintf('A%ib%i_test',A#,b#)}));
Please excuse the naming convention, it is for representative purposes only.

回答 (1 件)

Stephen23
Stephen23 2021 年 11 月 18 日
C = {'A1b1';'A1b2';'A1b1_test'};
cellfun(@mkdir,C)
S = dir('./*');
S.name
ans = '.'
ans = '..'
ans = 'A1b1'
ans = 'A1b1_test'
ans = 'A1b2'
S(ismember({S.name},{'.','..'})) = [];
S(endsWith({S.name},'_test')) = [];
S.name
ans = 'A1b1'
ans = 'A1b2'

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

製品


リリース

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by